Skip to content

Commit

Permalink
[FABG-749] Channel Client: MVCC Read Conflict Test
Browse files Browse the repository at this point in the history
Change-Id: Idaac300b5538bc639b927bf5cc22c0ea08d0e43b
Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Aug 29, 2018
1 parent b2585b7 commit c8e1c6c
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/integration/pkg/client/channel/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ package channel

import (
"strings"
"sync"
"testing"
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/multi"

pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -114,6 +117,69 @@ func TestChannelClient(t *testing.T) {
//test if CCEvents for chaincode events are in sync when new channel client are created
// for each transaction
testMultipleClientChaincodeEventLoop(t, chaincodeID)

testChannelClientMvccReadConflictWithRetry(t, chaincodeID, chClient)

testChannelClientMvccReadConflict(t, chaincodeID, chClient)

}

func testChannelClientMvccReadConflictWithRetry(t *testing.T, chaincodeID string, chClient *channel.Client) {

var wg sync.WaitGroup

maxAttempts := 2
for i := 0; i < maxAttempts; i++ {
wg.Add(1)
go func(attempt int) {
defer wg.Done()
response, err := chClient.Execute(
channel.Request{
ChaincodeID: chaincodeID,
Fcn: "invoke",
Args: integration.ExampleCCDefaultTxArgs(),
},
channel.WithRetry(retry.DefaultChannelOpts),
)

require.NoError(t, err, "Failed to move funds for request #%d", attempt)
assert.Equal(t, pb.TxValidationCode_VALID, response.TxValidationCode, "Expecting TxValidationCode to be TxValidationCode_VALID")
}(i)
}
wg.Wait()

}

func testChannelClientMvccReadConflict(t *testing.T, chaincodeID string, chClient *channel.Client) {

var errMtx sync.Mutex
var wg sync.WaitGroup
errs := multi.Errors{}

maxAttempts := 3
for i := 0; i < maxAttempts; i++ {
wg.Add(1)
go func(attempt int) {
defer wg.Done()
_, err := chClient.Execute(
channel.Request{
ChaincodeID: chaincodeID,
Fcn: "invoke",
Args: integration.ExampleCCDefaultTxArgs(),
},
)
if err != nil {
errMtx.Lock()
errs = append(errs, err)
errMtx.Unlock()
return
}
}(i)
}
wg.Wait()

assert.True(t, len(errs) > 0)
assert.True(t, strings.Contains(errs[0].Error(), "MVCC_READ_CONFLICT"))
}

func testDuplicateTargets(t *testing.T, chaincodeID string, chClient *channel.Client, key string, args [][]byte) {
Expand Down

0 comments on commit c8e1c6c

Please sign in to comment.