From ef3ec190d0d49269ea20e78a13e945fe2a7030ba Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 4 Apr 2024 10:53:52 +0300 Subject: [PATCH] rpcsrv: allow one-block slippage in TestWSClient_SubscriptionsCompat Close #2956. The failure reason is similar to the one described in #3396 for TestNotary: Blockchain's notificationDispatcher is listening to block events from storeBlock via separate channel. By the moment single block addition is finished, notification may or may not be properly handled by notificationDispatcher, especially given the fact that our runners are slow. As a result, assert.Eventually with 1-second awaiting period may fail. This issue is solved by adding one more block, because the second AddBlock finishes only when it sends block addition event to notificationDispatcher loop, which means that the previous event was handled. Signed-off-by: Anna Shaleva --- pkg/services/rpcsrv/client_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index cd4b00a88..f09c43cf3 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -2124,19 +2124,20 @@ func TestWSClient_SubscriptionsCompat(t *testing.T) { blocks := getTestBlocks(t) bCount := uint32(0) - getData := func(t *testing.T) (*block.Block, byte, util.Uint160, string, string) { + getData := func(t *testing.T) (*block.Block, *block.Block, byte, util.Uint160, string, string) { b1 := blocks[bCount] primary := b1.PrimaryIndex tx := b1.Transactions[0] sender := tx.Sender() ntfName := "Transfer" st := vmstate.Halt.String() - bCount++ - return b1, primary, sender, ntfName, st + b2 := blocks[bCount+1] + bCount += 2 + return b1, b2, primary, sender, ntfName, st } checkRelevant := func(t *testing.T, filtered bool) { - b, primary, sender, ntfName, st := getData(t) + b, bNext, primary, sender, ntfName, st := getData(t) var ( bID, txID, ntfID, aerID string blockCh = make(chan *block.Block) @@ -2212,6 +2213,10 @@ func TestWSClient_SubscriptionsCompat(t *testing.T) { // Accept the next block and wait for events. require.NoError(t, chain.AddBlock(b)) + // Blockchain's events channel is not buffered, and thus, by adding one more extra block + // we're ensuring that the previous block event receiving was successfully handled by Blockchain's + // notificationDispatcher loop. Once we're sure in that, we may start to check the actual notifications. + require.NoError(t, chain.AddBlock(bNext)) assert.Eventually(t, func() bool { lock.RLock() defer lock.RUnlock()