Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 1610d6a

Browse files
author
Baha Shaaban
committed
[FAB-12464] fix additional z build errors
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>
1 parent 6a3c34e commit 1610d6a

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

pkg/common/errors/retry/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ var TestRetryableCodes = map[status.Group][]status.Code{
178178
status.PrematureChaincodeExecution,
179179
status.ChaincodeAlreadyLaunching,
180180
status.ChaincodeNameNotFound,
181+
status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
181182
},
182183
status.EndorserServerStatus: {
183184
status.Code(common.Status_SERVICE_UNAVAILABLE),

test/integration/base_test_setup.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,20 +450,16 @@ func GetKeyName(t *testing.T) string {
450450
//ResetKeys resets given set of keys in example cc to given value
451451
func ResetKeys(t *testing.T, ctx contextAPI.ChannelProvider, chaincodeID, value string, keys ...string) {
452452
chClient, err := channel.New(ctx)
453-
if err != nil {
454-
t.Fatalf("Failed to create new channel client for reseting keys: %s", err)
455-
}
453+
require.NoError(t, err, "Failed to create new channel client for resetting keys")
456454
for _, key := range keys {
457455
// Synchronous transaction
458-
_, err := chClient.Execute(
456+
_, e := chClient.Execute(
459457
channel.Request{
460458
ChaincodeID: chaincodeID,
461459
Fcn: "invoke",
462460
Args: ExampleCCTxSetArgs(key, value),
463461
},
464462
channel.WithRetry(retry.DefaultChannelOpts))
465-
if err != nil {
466-
t.Fatalf("Failed to reset keys: %s", err)
467-
}
463+
require.NoError(t, e, "Failed to reset keys")
468464
}
469465
}

test/integration/pkg/client/channel/channel_client_pvt_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func TestChannelClientRollsBackPvtDataIfMvccReadConflict(t *testing.T) {
318318
channel.WithRetry(retry.TestRetryOpts),
319319
)
320320
require.NoErrorf(t, err, "error attempting to read private data")
321+
require.NotEmptyf(t, resp.Payload, "reading private data returned empty response")
321322

322323
actual, err := strconv.Atoi(string(resp.Payload))
323324
require.NoError(t, err)

test/integration/pkg/client/channel/channel_client_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,20 @@ func testQuery(t *testing.T, chClient *channel.Client, expected string, ccID, ke
335335
for r := 0; r < 10; r++ {
336336
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs(key)},
337337
channel.WithRetry(retry.DefaultChannelOpts))
338-
require.NoError(t, err, "failed to invoke example cc")
338+
if err == nil {
339+
actual := string(response.Payload)
340+
if actual == expected {
341+
return
342+
}
339343

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

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

test/integration/pkg/fabsdk/provider/sdk_provider_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestDynamicSelection(t *testing.T) {
5050

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

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

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

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

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

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

0 commit comments

Comments
 (0)