Skip to content

Commit

Permalink
[FAB-12464] fix additional z build errors
Browse files Browse the repository at this point in the history
	Avoid error check in testQuery() to force a retry query
	in case the peers don't have the latest key values in
	the ledger. This happens in z builds as it processes
	testQuery() before ResetKeys() results are propagated
	to all the peers.

	Apparently x86 build propagates the key values to all
	peers before subsequent tests query/update them.
	This is why x86 build never complain about these issues.

	Also added MVCC_READ_CONFLICT code to the test retryable
	codes to ensure withRetry() do retry invoking the CCs on
	this error.

Change-Id: Id8f487cf926da5c225ce3e36ce48261c89a560a5
Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Oct 17, 2018
1 parent 6a3c34e commit 1610d6a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions pkg/common/errors/retry/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ var TestRetryableCodes = map[status.Group][]status.Code{
status.PrematureChaincodeExecution,
status.ChaincodeAlreadyLaunching,
status.ChaincodeNameNotFound,
status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
},
status.EndorserServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
Expand Down
10 changes: 3 additions & 7 deletions test/integration/base_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,20 +450,16 @@ func GetKeyName(t *testing.T) string {
//ResetKeys resets given set of keys in example cc to given value
func ResetKeys(t *testing.T, ctx contextAPI.ChannelProvider, chaincodeID, value string, keys ...string) {
chClient, err := channel.New(ctx)
if err != nil {
t.Fatalf("Failed to create new channel client for reseting keys: %s", err)
}
require.NoError(t, err, "Failed to create new channel client for resetting keys")
for _, key := range keys {
// Synchronous transaction
_, err := chClient.Execute(
_, e := chClient.Execute(
channel.Request{
ChaincodeID: chaincodeID,
Fcn: "invoke",
Args: ExampleCCTxSetArgs(key, value),
},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to reset keys: %s", err)
}
require.NoError(t, e, "Failed to reset keys")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func TestChannelClientRollsBackPvtDataIfMvccReadConflict(t *testing.T) {
channel.WithRetry(retry.TestRetryOpts),
)
require.NoErrorf(t, err, "error attempting to read private data")
require.NotEmptyf(t, resp.Payload, "reading private data returned empty response")

actual, err := strconv.Atoi(string(resp.Payload))
require.NoError(t, err)
Expand Down
16 changes: 11 additions & 5 deletions test/integration/pkg/client/channel/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ func testQuery(t *testing.T, chClient *channel.Client, expected string, ccID, ke
for r := 0; r < 10; r++ {
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs(key)},
channel.WithRetry(retry.DefaultChannelOpts))
require.NoError(t, err, "failed to invoke example cc")
if err == nil {
actual := string(response.Payload)
if actual == expected {
return
}

actual := string(response.Payload)
if actual == expected {
return
t.Logf("On Attempt [%d / %d]: Response didn't match expected value [%s, %s]", r, maxRetries, actual, expected)
} else {
t.Logf("On Attempt [%d / %d]: failed to invoke example cc '%s' with Args:[%+v], error: %+v", r, maxRetries, ccID, integration.ExampleCCQueryArgs(key), err)
if r < 9 {
t.Logf("will retry in %v", retrySleep)
}
}

t.Logf("On Attempt [%d / %d]: Response didn't match expected value [%s, %s]", r, maxRetries, actual, expected)
time.Sleep(retrySleep)
}

Expand Down
14 changes: 4 additions & 10 deletions test/integration/pkg/fabsdk/provider/sdk_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDynamicSelection(t *testing.T) {

chaincodeID := integration.GenerateExampleID(false)
err = integration.PrepareExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chaincodeID)
require.Nil(t, err, "InstallAndInstantiateExampleCC return error")
require.NoError(t, err, "InstallAndInstantiateExampleCC returned error")

//prepare contexts
org1ChannelClientContext := sdk.ChannelContext(testSetup.ChannelID, fabsdk.WithUser(org1User), fabsdk.WithOrg(org1Name))
Expand All @@ -59,23 +59,17 @@ func TestDynamicSelection(t *testing.T) {
integration.ResetKeys(t, org1ChannelClientContext, chaincodeID, "200", aKey, bKey)

chClient, err := channel.New(org1ChannelClientContext)
if err != nil {
t.Fatalf("Failed to create new channel client: %s", err)
}
require.NoError(t, err, "Failed to create new channel client")

response, err := chClient.Query(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: queryArg},
channel.WithRetry(retry.TestRetryOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
require.NoError(t, err, "Failed to query funds, ccID: %s, queryArgs: [%+v]", chaincodeID, queryArg)
value := response.Payload

// Move funds
response, err = chClient.Execute(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: moveTxArg},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
require.NoError(t, err, "Failed to move funds, ccID: %s, queryArgs:[%+v]", chaincodeID, moveTxArg)

valueInt, _ := strconv.Atoi(string(value))
verifyValue(t, chClient, queryArg, valueInt+1, chaincodeID)
Expand Down

0 comments on commit 1610d6a

Please sign in to comment.