From f95004ad831d01fa852b2076f43f670bde9ffc29 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 1 Apr 2024 20:21:41 +0300 Subject: [PATCH] services: fix race in TestNotary Close #3366. Roll back the test structure to the one that it has before d2a7162217e2c429600ff583690caeebc07e28a2. Add one extra block to ensure that main transaction won't be finilized. Add NVB increment slippage to avoid race between the first fallback acceptance and block acceptance. Add NVB increment slippage to the rest of fallbacks for test structure unification. Signed-off-by: Anna Shaleva --- pkg/services/notary/core_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/services/notary/core_test.go b/pkg/services/notary/core_test.go index 802cd4149..69bf876d2 100644 --- a/pkg/services/notary/core_test.go +++ b/pkg/services/notary/core_test.go @@ -591,23 +591,27 @@ func TestNotary(t *testing.T) { // PostPersist: different NVBs // check OnNewRequest with finalization error and different NVBs setFinalizeWithError(true) - requests, requesters = checkCompleteStandardRequest(t, 5, false, 1, 2, 3, 4, 5) + // Introduce some slippage between first and second fallback NVBs in order to avoid possible race caused by early + // first fallback transaction acceptance. The rest of fallbacks follow X+4 NVB pattern for testing code shortness. + requests, requesters = checkCompleteStandardRequest(t, 5, false, 1, 7, 11, 15, 19) checkFallbackTxs(t, requests, false) // generate blocks to reach the most earlier fallback's NVB - e.GenerateNewBlocks(t, int(nvbDiffFallback)) + e.GenerateNewBlocks(t, int(nvbDiffFallback+1)) require.NoError(t, err) // check PostPersist for valid fallbacks without finalisation error - // Add block before allowing tx to finalize to exclude race condition when - // main transaction is finalized between `finalizeWithError` restore and adding new block. + // Add a block before allowing tx to be finalized without error to exclude race condition when + // main transaction is finalized between `finalizeWithError` disabling and new block addition. e.AddNewBlock(t) setFinalizeWithError(false) - for i := range requests[1:] { + for i := range requests { + e.AddNewBlock(t) + e.AddNewBlock(t) + e.AddNewBlock(t) e.AddNewBlock(t) - _ = getCompletedTx(t, true, requests[i+1].FallbackTransaction.Hash()) checkMainTx(t, requesters, requests, len(requests), false) - checkFallbackTxs(t, requests[:i+2], true) - checkFallbackTxs(t, requests[i+2:], false) + checkFallbackTxs(t, requests[:i+1], true) + checkFallbackTxs(t, requests[i+1:], false) } // OnRequestRemoval: missing account