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

Commit de7bf5f

Browse files
committed
[FABG-748] fix for intermittent SeekTypes test failure
Change-Id: Id496f84510cbaef1d0d2ef5dffe21441824ae83d Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
1 parent c8e1c6c commit de7bf5f

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

test/integration/pkg/client/channel/channel_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestChannelClient(t *testing.T) {
9393
testQuery(t, chClient, "202", chaincodeID, bKey)
9494

9595
// Test register and receive chaincode event
96-
testChaincodeEvent(chaincodeID, chClient, t, moveOneTx)
96+
testChaincodeEvent(t, chClient, moveOneTx, chaincodeID)
9797

9898
// Verify transaction with chain code event completed
9999
testQuery(t, chClient, "203", chaincodeID, bKey)
@@ -440,7 +440,7 @@ func testInvokeHandler(t *testing.T, chClient *channel.Client, ccID string, args
440440
}
441441
}
442442

443-
func testChaincodeEvent(ccID string, chClient *channel.Client, t *testing.T, args [][]byte) {
443+
func testChaincodeEvent(t *testing.T, chClient *channel.Client, args [][]byte, ccID string) {
444444

445445
eventID := "test([a-zA-Z]+)"
446446

test/integration/pkg/fab/eventclient_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/pkg/errors"
2222
"github.com/stretchr/testify/require"
2323

24-
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
2524
"github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/seek"
2625
"github.com/hyperledger/fabric-sdk-go/test/integration"
2726
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
@@ -272,18 +271,27 @@ func TestMultipleEventsBySeekTypes(t *testing.T) {
272271
testSetup := mainTestSetup
273272

274273
//Run with seek type default and test behaviour
275-
274+
//If seek type is default, then event dispatcher uses first block only for block height calculations, it doesn't publish anything
275+
//to event channel, and first event we get from event channel actually belongs to first transaction after registration.
276+
var txIDMatched bool
276277
for i := 0; i < 4; i++ {
277-
testSeekTypeDefault(t, testSetup, chaincodeID)
278+
txIDMatched = testSeekTypeDefault(t, testSetup, chaincodeID)
279+
//In case of seektype DEFAULT, txID from event always match with transaction happened after event registration
280+
require.True(t, txIDMatched, "TxID from one of the event didn't match with test transaction TxID")
278281
}
279282

280283
//Run with seek type newest and test behaviour
284+
//If seek type is newest then the first event we get from event channel is not related to the first transaction happened after registration, it is
285+
//actually latest block from the chain. So TxID from event will not always match with TxID from test transaction
286+
txIDMatched = true
281287
for i := 0; i < 4; i++ {
282-
testSeekTypeNewest(t, testSetup, chaincodeID)
288+
txIDMatched = txIDMatched && testSeekTypeNewest(t, testSetup, chaincodeID)
283289
}
290+
//In case of seektype NEWEST, txID from event will not always match with transaction happened after event registration
291+
require.False(t, txIDMatched, "TxID from each event matched with TxID of transaction after each registration, which isn't conventional seektype NEWEST behavior")
284292
}
285293

286-
func testSeekTypeDefault(t *testing.T, testSetup *integration.BaseSetupImpl, chaincodeID string) {
294+
func testSeekTypeDefault(t *testing.T, testSetup *integration.BaseSetupImpl, chaincodeID string) bool {
287295
//create new sdk
288296
sdk, err := fabsdk.New(integration.ConfigBackend)
289297
require.NoError(t, err, "failed to get new sdk instance")
@@ -298,10 +306,10 @@ func testSeekTypeDefault(t *testing.T, testSetup *integration.BaseSetupImpl, cha
298306
eventService, err := chContext.ChannelService().EventService()
299307
require.NoError(t, err, "error getting event service")
300308

301-
testChannelEventsSeekOptions(t, testSetup, sdk, chContext, chaincodeID, false, eventService, "")
309+
return testChannelEventsSeekOptions(t, testSetup, sdk, chaincodeID, false, eventService, "")
302310
}
303311

304-
func testSeekTypeNewest(t *testing.T, testSetup *integration.BaseSetupImpl, chaincodeID string) {
312+
func testSeekTypeNewest(t *testing.T, testSetup *integration.BaseSetupImpl, chaincodeID string) bool {
305313
//create new sdk
306314
sdk, err := fabsdk.New(integration.ConfigBackend)
307315
require.NoError(t, err, "failed to get new sdk instance")
@@ -316,10 +324,10 @@ func testSeekTypeNewest(t *testing.T, testSetup *integration.BaseSetupImpl, chai
316324
eventService, err := chContext.ChannelService().EventService(deliverclient.WithSeekType(seek.Newest))
317325
require.NoError(t, err, "error getting event service")
318326

319-
testChannelEventsSeekOptions(t, testSetup, sdk, chContext, chaincodeID, false, eventService, seek.Newest)
327+
return testChannelEventsSeekOptions(t, testSetup, sdk, chaincodeID, false, eventService, seek.Newest)
320328
}
321329

322-
func testChannelEventsSeekOptions(t *testing.T, testSetup *integration.BaseSetupImpl, sdk *fabsdk.FabricSDK, chContext context.Channel, chainCodeID string, blockEvents bool, eventService fab.EventService, seekType seek.Type) {
330+
func testChannelEventsSeekOptions(t *testing.T, testSetup *integration.BaseSetupImpl, sdk *fabsdk.FabricSDK, chainCodeID string, blockEvents bool, eventService fab.EventService, seekType seek.Type) bool {
323331

324332
//get transactor
325333
_, cancel, transactor, err := getTransactor(sdk, testSetup.ChannelID, "Admin", testSetup.OrgID)
@@ -359,16 +367,10 @@ func testChannelEventsSeekOptions(t *testing.T, testSetup *integration.BaseSetup
359367
}
360368
case <-time.After(eventTimeWindow):
361369
t.Fatal("Timeout waiting for event")
362-
return
370+
return false
363371
}
364372

365-
//If seek type is newest then the first event we get from event channel is not related to the first transaction happened after registration, it is
366-
//actually latest block from the chain
367-
require.Equal(t, seekType == seek.Newest, txID != event.TxID, "for seek type[%s], txID [%s], event.txID[%s] ,condition didn't match", seekType, txID, event.TxID)
368-
369-
//If seek type is default, then event dispatcher uses first block only for block height calculations, it doesn't publish anything
370-
//to event channel, and first event we get from event channel actually belongs to first transaction after registration.
371-
require.Equal(t, seekType == "", txID == event.TxID, "for seek type[%s], txID [%s], event.txID[%s] ,condition didn't match", seekType, txID, event.TxID)
373+
return txID == event.TxID
372374
}
373375

374376
//TestEventClientWithMVCCReadConflicts tests behavior of chaincode events when MVCC_READ_CONFLICT happens

0 commit comments

Comments
 (0)