Skip to content

Commit

Permalink
Merge "[FAB-5238] Poll results to fix intermittent failure"
Browse files Browse the repository at this point in the history
  • Loading branch information
fqutishat authored and Gerrit Code Review committed Jul 11, 2017
2 parents 4e0def9 + 3f9b996 commit 6450c43
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ package orgs

import (
"fmt"
"math"
"strconv"
"testing"
"time"

"github.com/hyperledger/fabric-sdk-go/api/apitxn"
fabrictxn "github.com/hyperledger/fabric-sdk-go/pkg/fabric-txn"
)

const (
pollRetries = 5
)

// TestOrgsEndToEnd creates a channel with two organisations, installs chaincode
// on each of them, and finally invokes a transaction on an org2 peer and queries
// the result from an org1 peer
Expand Down Expand Up @@ -48,18 +54,35 @@ func TestOrgsEndToEnd(t *testing.T) {
failTestIfError(err, t)

// Assert changed value on org1 peer
var finalValue int
for i := 0; i < pollRetries; i++ {
finalValue = queryOrg1Peer(t)
// If value has not propogated sleep with exponential backoff
if initialValue+1 != finalValue {
backoffFactor := math.Pow(2, float64(i))
time.Sleep(time.Millisecond * 50 * time.Duration(backoffFactor))
} else {
break
}
}
if initialValue+1 != finalValue {
t.Fatalf("Org1 invoke result was not propagated to org2. Expected %d, got: %d",
(initialValue + 1), finalValue)
}
}

func queryOrg1Peer(t *testing.T) int {
fcn := "invoke"

orgTestClient.SetUserContext(org1User)
orgTestChannel.SetPrimaryPeer(orgTestPeer0)
result, err = fabrictxn.QueryChaincode(orgTestClient, orgTestChannel,
result, err := fabrictxn.QueryChaincode(orgTestClient, orgTestChannel,
"exampleCC", fcn, generateQueryArgs())
failTestIfError(err, t)
finalValue, err := strconv.Atoi(result)
failTestIfError(err, t)

if initialValue+1 != finalValue {
t.Fatalf("Org1 invoke result was not propagated to org2. Expected %d, got: %d",
(initialValue + 1), finalValue)
}
return finalValue
}

func generateQueryArgs() []string {
Expand Down

0 comments on commit 6450c43

Please sign in to comment.