Skip to content

Commit

Permalink
[FAB-10898] Fix integration tests by adding retries
Browse files Browse the repository at this point in the history
Change-Id: I3c66787dcf9815de337bc7f437b28fe8567cd853
Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
  • Loading branch information
bstasyszyn authored and troyronda committed Jun 27, 2018
1 parent 6decf5f commit a7dfa53
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 16 deletions.
10 changes: 7 additions & 3 deletions test/integration/e2e/no_orderer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"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 @@ -54,7 +55,8 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts

response, err := client.Query(
channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithTargetFilter(discoveryFilter))
channel.WithTargetFilter(discoveryFilter),
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
Expand All @@ -79,7 +81,8 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts
}

func moveFunds(response channel.Response, client *channel.Client, t *testing.T, notifier <-chan *fab.CCEvent, eventID string, value []byte) {
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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand All @@ -90,7 +93,8 @@ func moveFunds(response channel.Response, client *channel.Client, t *testing.T,
t.Fatalf("Did NOT receive CC event for eventId(%s)\n", eventID)
}
// Verify move funds transaction result
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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func changeBlockState(t *testing.T, client *channel.Client, chaincodeID string)
Fcn: "invoke",
Args: integration.ExampleCCQueryArgs(),
}
resp, err := client.Query(req)
resp, err := client.Query(req, channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
return "", errors.WithMessage(err, "query funds failed")
}
Expand All @@ -158,7 +158,7 @@ func changeBlockState(t *testing.T, client *channel.Client, chaincodeID string)
return "", errors.WithMessage(err, "move funds failed")
}

resp, err = client.Query(req)
resp, err = client.Query(req, channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
return "", errors.WithMessage(err, "query funds failed")
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func moveFundsAndGetTxID(t *testing.T, client *channel.Client, chaincodeID strin
Args: integration.ExampleCCTxArgs(),
TransientMap: transientDataMap,
}
resp, err := client.Execute(req)
resp, err := client.Execute(req, channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
return "", errors.WithMessage(err, "execute move funds failed")
}
Expand Down
3 changes: 2 additions & 1 deletion test/integration/revoked/revoked_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ func queryCC(org1ChannelClientContext contextAPI.ChannelProvider, t *testing.T)
// Error in container is :
// .... identity 0 does not satisfy principal:
// Could not validate identity against certification chain, err The certificate has been revoked
_, err = chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
_, err = chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChannelOpts))
if err == nil {
t.Fatal("Expected error: '....Description: could not find chaincode with name 'exampleCC',,, ")
}
Expand Down
9 changes: 6 additions & 3 deletions test/integration/sdk/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestChannelClient(t *testing.T) {
Fcn: "invoke",
Args: integration.ExampleCCTxArgs(),
TransientMap: transientDataMap,
})
},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down Expand Up @@ -338,7 +339,8 @@ func testChaincodeEvent(ccID string, chClient *channel.Client, t *testing.T) {
}
defer chClient.UnregisterChaincodeEvent(reg)

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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand All @@ -365,7 +367,8 @@ func testChaincodeEventListener(ccID string, chClient *channel.Client, listener
}
defer chClient.UnregisterChaincodeEvent(reg)

response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: append(integration.ExampleCCTxArgs(), []byte(eventID))})
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: append(integration.ExampleCCTxArgs(), []byte(eventID))},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down
4 changes: 3 additions & 1 deletion test/integration/sdk/custom_cryptosuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
bccspSw "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/factory/sw"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"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/core/cryptosuite"
"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/wrapper"
Expand Down Expand Up @@ -87,7 +88,8 @@ func TestEndToEndForCustomCryptoSuite(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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
Expand Down
10 changes: 7 additions & 3 deletions test/integration/sdk/events_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/event"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/seek"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
Expand Down Expand Up @@ -96,7 +97,8 @@ func testCCEvent(ccID string, chClient *channel.Client, eventClient *event.Clien
}
defer eventClient.Unregister(reg)

response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: append(integration.ExampleCCTxArgs(), []byte(eventID))})
response, err := chClient.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: append(integration.ExampleCCTxArgs(), []byte(eventID))},
channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down Expand Up @@ -127,7 +129,8 @@ func testRegisterBlockEvent(ccID string, chClient *channel.Client, eventClient *
}
defer eventClient.Unregister(breg)

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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand All @@ -154,7 +157,8 @@ func testRegisterFilteredBlockEvent(ccID string, chClient *channel.Client, event
}
defer eventClient.Unregister(fbreg)

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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion test/integration/sdk/sdk_parent_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestParentContext(t *testing.T) {
}

_, err = chClient.Query(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithParentContext(parentContext))
channel.WithParentContext(parentContext),
channel.WithRetry(retry.DefaultChannelOpts))
if err == nil || !strings.Contains(err.Error(), "request timed out or been cancelled") {
t.Fatalf("expected context cancelled error but got: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion test/integration/sdk/sdk_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func TestDynamicSelection(t *testing.T) {
success := false
for i := 0; i < 5; i++ {
// Verify move funds transaction result
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.DefaultChannelOpts))
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}
Expand Down

0 comments on commit a7dfa53

Please sign in to comment.