@@ -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