Skip to content

Commit

Permalink
[FAB-9188] Add retries to integration tests
Browse files Browse the repository at this point in the history
Change-Id: I67d6df1b42cba42c0a85e0a15acdba6f9b204a9b
Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
  • Loading branch information
d1vyank committed Mar 27, 2018
1 parent 6880d84 commit b02be7a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
9 changes: 9 additions & 0 deletions pkg/common/errors/retry/defaults.go
Expand Up @@ -35,6 +35,15 @@ var DefaultOpts = Opts{
RetryableCodes: DefaultRetryableCodes,
}

// DefaultChClientOpts default retry options for the channel client
var DefaultChClientOpts = Opts{
Attempts: DefaultAttempts,
InitialBackoff: DefaultInitialBackoff,
MaxBackoff: DefaultMaxBackoff,
BackoffFactor: DefaultBackoffFactor,
RetryableCodes: ChannelClientRetryableCodes,
}

// DefaultRetryableCodes these are the error codes, grouped by source of error,
// that are considered to be transient error conditions by default
var DefaultRetryableCodes = map[status.Group][]status.Code{
Expand Down
10 changes: 7 additions & 3 deletions test/integration/e2e/end_to_end.go
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

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

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

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

// Move funds
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down
22 changes: 15 additions & 7 deletions test/integration/orgs/multiple_orgs_test.go
Expand Up @@ -15,6 +15,7 @@ import (
"time"

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

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

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

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

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

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

// Org2 user moves funds (dynamic selection will inspect chaincode policy to determine endorsers)
_, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
_, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down Expand Up @@ -407,7 +414,8 @@ func verifyValue(t *testing.T, chClient *channel.Client, expected int) {
var valueInt int
for i := 0; i < pollRetries; i++ {
// Query final value on org1 peer
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets(orgTestPeer0))
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets(orgTestPeer0),
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}
Expand Down
10 changes: 7 additions & 3 deletions test/integration/sdk/channel_client_test.go
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
Expand Down Expand Up @@ -120,7 +121,8 @@ func TestChannelClient(t *testing.T) {

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

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

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()})
response, err := chClient.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Query returned error: %s", err)
}
Expand All @@ -141,7 +144,8 @@ func testQueryWithOpts(expected string, ccID string, chClient *channel.Client, t
}

func testTransaction(ccID string, chClient *channel.Client, t *testing.T) {
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down
7 changes: 5 additions & 2 deletions test/integration/sdk/sdk_provider_test.go
Expand Up @@ -12,6 +12,7 @@ import (

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

"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"

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

response, err := chClient.Query(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
response, err := chClient.Query(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
value := response.Payload

// Move funds
response, err = chClient.Execute(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
response, err = chClient.Execute(channel.Request{ChaincodeID: chainCodeID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down

0 comments on commit b02be7a

Please sign in to comment.