Skip to content

Commit

Permalink
Move the for-loop that checks that the dispatcher got behind at least…
Browse files Browse the repository at this point in the history
… once, to outside the per-block loop

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
  • Loading branch information
matthew1001 committed Sep 3, 2024
1 parent 2833410 commit e88e51f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/confirmations/confirmed_block_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestCBLDispatcherFallsBehindHead(t *testing.T) {

id := fftypes.NewUUID()

blocks := testBlockArray(100)
blocks := testBlockArray(30)

mbiHash := mca.On("BlockInfoByHash", mock.Anything, mock.Anything)
mbiHash.Run(func(args mock.Arguments) { mockBlockHashReturn(mbiHash, args, blocks) })
Expand All @@ -353,15 +353,18 @@ func TestCBLDispatcherFallsBehindHead(t *testing.T) {
})
}

// The dispatches should have been added, until it got too far ahead
// and then set to nil.
for cbl.newHeadToAdd != nil {
time.Sleep(1 * time.Millisecond)
}

// For N-5 (e.g. 15 blocks for a 20 block list) check that we get a dispatch saying that each block 0-14 has been confirmed
for i := 0; i < len(blocks)-bcm.requiredConfirmations; i++ {
// The dispatches should have been added, until it got too far ahead
// and then set to nil.
for cbl.newHeadToAdd != nil {
time.Sleep(1 * time.Millisecond)
}
// We should get an event-stream dispatch for blocks N-5 (e.g. 0-15 for a 20 block list)
b := <-esDispatch
assert.Equal(t, b.BlockEvent.BlockNumber.Uint64(), blocks[i].BlockNumber.Uint64())
assert.Equal(t, b.BlockEvent.BlockInfo, blocks[i].BlockInfo)
assert.Equal(t, blocks[i].BlockNumber.Uint64(), b.BlockEvent.BlockNumber.Uint64())
assert.Equal(t, blocks[i].BlockInfo, b.BlockEvent.BlockInfo)
}

time.Sleep(1 * time.Millisecond)
Expand Down

0 comments on commit e88e51f

Please sign in to comment.