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

Commit b02be7a

Browse files
committed
[FAB-9188] Add retries to integration tests
Change-Id: I67d6df1b42cba42c0a85e0a15acdba6f9b204a9b Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
1 parent 6880d84 commit b02be7a

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

pkg/common/errors/retry/defaults.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ var DefaultOpts = Opts{
3535
RetryableCodes: DefaultRetryableCodes,
3636
}
3737

38+
// DefaultChClientOpts default retry options for the channel client
39+
var DefaultChClientOpts = Opts{
40+
Attempts: DefaultAttempts,
41+
InitialBackoff: DefaultInitialBackoff,
42+
MaxBackoff: DefaultMaxBackoff,
43+
BackoffFactor: DefaultBackoffFactor,
44+
RetryableCodes: ChannelClientRetryableCodes,
45+
}
46+
3847
// DefaultRetryableCodes these are the error codes, grouped by source of error,
3948
// that are considered to be transient error conditions by default
4049
var DefaultRetryableCodes = map[status.Group][]status.Code{

test/integration/e2e/end_to_end.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
1516
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/status"
1617
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
1718
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
@@ -129,7 +130,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
129130
t.Fatalf("Failed to create new channel client: %s", err)
130131
}
131132

132-
response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
133+
response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
134+
channel.WithRetry(retry.DefaultChClientOpts))
133135
if err != nil {
134136
t.Fatalf("Failed to query funds: %s", err)
135137
}
@@ -145,7 +147,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
145147
defer client.UnregisterChaincodeEvent(reg)
146148

147149
// Try calling unknown function call and expect an error
148-
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCTxArgs()})
150+
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCTxArgs()},
151+
channel.WithRetry(retry.DefaultChClientOpts))
149152
if err == nil {
150153
t.Fatal("Should have failed with dummy function")
151154
}
@@ -159,7 +162,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
159162
}
160163

161164
// Move funds
162-
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
165+
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
166+
channel.WithRetry(retry.DefaultChClientOpts))
163167
if err != nil {
164168
t.Fatalf("Failed to move funds: %s", err)
165169
}

test/integration/orgs/multiple_orgs_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/multi"
18+
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
1819
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/status"
1920
contextAPI "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
2021
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
@@ -197,7 +198,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
197198
}
198199

199200
// Call with a dummy function and expect a fail with multiple errors
200-
response, err := chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCQueryArgs()})
201+
response, err := chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCQueryArgs()},
202+
channel.WithRetry(retry.DefaultChClientOpts))
201203
if err == nil {
202204
t.Fatal("Should have failed with dummy function")
203205
}
@@ -217,7 +219,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
217219
}
218220

219221
// Org1 user queries initial value on both peers
220-
response, err = chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
222+
response, err = chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
223+
channel.WithRetry(retry.DefaultChClientOpts))
221224
if err != nil {
222225
t.Fatalf("Failed to query funds: %s", err)
223226
}
@@ -265,7 +268,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
265268
}
266269

267270
// Org2 user moves funds on org2 peer
268-
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer1))
271+
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer1),
272+
channel.WithRetry(retry.DefaultChClientOpts))
269273
if err != nil {
270274
t.Fatalf("Failed to move funds: %s", err)
271275
}
@@ -336,13 +340,15 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
336340
assert.NotEmpty(t, upgradeResp, "transaction response should be populated")
337341

338342
// Org2 user moves funds on org2 peer (cc policy fails since both Org1 and Org2 peers should participate)
339-
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer1))
343+
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer1),
344+
channel.WithRetry(retry.DefaultChClientOpts))
340345
if err == nil {
341346
t.Fatalf("Should have failed to move funds due to cc policy")
342347
}
343348

344349
// Org2 user moves funds (cc policy ok since we have provided peers for both Orgs)
345-
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer0, orgTestPeer1))
350+
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer0, orgTestPeer1),
351+
channel.WithRetry(retry.DefaultChClientOpts))
346352
if err != nil {
347353
t.Fatalf("Failed to move funds: %s", err)
348354
}
@@ -379,7 +385,8 @@ func testWithOrg2(t *testing.T, expectedValue int) int {
379385
}
380386

381387
// Org2 user moves funds (dynamic selection will inspect chaincode policy to determine endorsers)
382-
_, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
388+
_, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
389+
channel.WithRetry(retry.DefaultChClientOpts))
383390
if err != nil {
384391
t.Fatalf("Failed to move funds: %s", err)
385392
}
@@ -407,7 +414,8 @@ func verifyValue(t *testing.T, chClient *channel.Client, expected int) {
407414
var valueInt int
408415
for i := 0; i < pollRetries; i++ {
409416
// Query final value on org1 peer
410-
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets(orgTestPeer0))
417+
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets(orgTestPeer0),
418+
channel.WithRetry(retry.DefaultChClientOpts))
411419
if err != nil {
412420
t.Fatalf("Failed to query funds after transaction: %s", err)
413421
}

test/integration/sdk/channel_client_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
1616
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke"
17+
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
1718
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
1819
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
1920
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
@@ -120,7 +121,8 @@ func TestChannelClient(t *testing.T) {
120121

121122
func testQuery(expected string, ccID string, chClient *channel.Client, t *testing.T) {
122123

123-
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
124+
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
125+
channel.WithRetry(retry.DefaultChClientOpts))
124126
if err != nil {
125127
t.Fatalf("Failed to invoke example cc: %s", err)
126128
}
@@ -131,7 +133,8 @@ func testQuery(expected string, ccID string, chClient *channel.Client, t *testin
131133
}
132134

133135
func testQueryWithOpts(expected string, ccID string, chClient *channel.Client, t *testing.T) {
134-
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
136+
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
137+
channel.WithRetry(retry.DefaultChClientOpts))
135138
if err != nil {
136139
t.Fatalf("Query returned error: %s", err)
137140
}
@@ -141,7 +144,8 @@ func testQueryWithOpts(expected string, ccID string, chClient *channel.Client, t
141144
}
142145

143146
func testTransaction(ccID string, chClient *channel.Client, t *testing.T) {
144-
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
147+
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
148+
channel.WithRetry(retry.DefaultChClientOpts))
145149
if err != nil {
146150
t.Fatalf("Failed to move funds: %s", err)
147151
}

test/integration/sdk/sdk_provider_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/hyperledger/fabric-sdk-go/test/integration"
1414

15+
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
1516
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
1617
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
1718

@@ -67,14 +68,16 @@ func TestDynamicSelection(t *testing.T) {
6768
t.Fatalf("Failed to create new channel client: %s", err)
6869
}
6970

70-
response, err := chClient.Query(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
71+
response, err := chClient.Query(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
72+
channel.WithRetry(retry.DefaultChClientOpts))
7173
if err != nil {
7274
t.Fatalf("Failed to query funds: %s", err)
7375
}
7476
value := response.Payload
7577

7678
// Move funds
77-
response, err = chClient.Execute(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
79+
response, err = chClient.Execute(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
80+
channel.WithRetry(retry.DefaultChClientOpts))
7881
if err != nil {
7982
t.Fatalf("Failed to move funds: %s", err)
8083
}

0 commit comments

Comments
 (0)