Skip to content

Commit

Permalink
[FAB-10895] Channel client test wait for propagation
Browse files Browse the repository at this point in the history
Change-Id: I5c9bb1d44fd4024dfb3e9f6421d7276479c266f5
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Jun 28, 2018
1 parent 68c81a3 commit 5f82d04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ func verifyTargetChangedBlockState(t *testing.T, client *channel.Client, chainco
return
}

t.Logf("On Attempt [%d / %d]: SendTransaction didn't change the QueryValue %d", r, maxRetries, expectedValue)
t.Logf("On Attempt [%d / %d]: Response didn't match expected value [%d, %d]", r, maxRetries, valueAfterInvokeInt, expectedValue)
time.Sleep(retrySleep)
}

t.Error("Exceeded max retries in verifyPeerChangedBlockState")
t.Fatal("Exceeded max retries")
}

func testQueryTransaction(t *testing.T, ledgerClient *ledger.Client, txID fab.TransactionID, targets []string) {
Expand Down
35 changes: 17 additions & 18 deletions test/integration/sdk/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestChannelClient(t *testing.T) {
}

// Verify transaction using query
testQueryWithOpts("201", chaincodeID, chClient, t)
testQuery("201", chaincodeID, chClient, t)

// transaction
nestedCCID := integration.GenerateRandomID()
Expand Down Expand Up @@ -192,27 +192,26 @@ func TestCCToCC(t *testing.T) {
}

func testQuery(expected string, ccID string, chClient *channel.Client, t *testing.T) {
const (
maxRetries = 10
retrySleep = 500 * time.Millisecond
)

response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to invoke example cc: %s", err)
}
for r := 0; r < 10; r++ {
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChannelOpts))
require.NoError(t, err, "failed to invoke example cc")

if string(response.Payload) != expected {
t.Fatalf("Expecting %s, got %s", expected, response.Payload)
}
}
actual := string(response.Payload)
if actual == expected {
return
}

func testQueryWithOpts(expected string, ccID string, chClient *channel.Client, t *testing.T) {
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Query returned error: %s", err)
}
if string(response.Payload) != expected {
t.Fatalf("Expecting %s, got %s", expected, response.Payload)
t.Logf("On Attempt [%d / %d]: Response didn't match expected value [%s, %s]", r, maxRetries, actual, expected)
time.Sleep(retrySleep)
}

t.Fatal("Exceeded max retries")
}

func testTransaction(ccID, nestedCCID string, chClient *channel.Client, t *testing.T) {
Expand Down

0 comments on commit 5f82d04

Please sign in to comment.