From f864f9e231c2c4bf6f29a3ebfc4a4791136e0c74 Mon Sep 17 00:00:00 2001 From: chris erway <51567+cce@users.noreply.github.com> Date: Fri, 14 Jan 2022 12:44:32 -0500 Subject: testing: Add slightly more coverage to TestAcctUpdatesLookupRetry (#3384) Add slightly more coverage to TestAcctUpdatesLookupRetry --- ledger/acctupdates_test.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 5f014985c..f1434b02f 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -1734,7 +1734,7 @@ func TestAcctUpdatesLookupRetry(t *testing.T) { sinkdata.Status = basics.NotParticipating accts[0][testSinkAddr] = sinkdata - ml := makeMockLedgerForTracker(t, false, 10, testProtocolVersion, accts) + ml := makeMockLedgerForTracker(t, true, 10, testProtocolVersion, accts) defer ml.Close() conf := config.GetDefaultLocal() @@ -1833,19 +1833,25 @@ func TestAcctUpdatesLookupRetry(t *testing.T) { break } - // release the postCommit lock, once au.lookupWithoutRewards hits au.accountsReadCond.Wait() + defer func() { // allow the postCommitUnlocked() handler to go through, even if test fails + <-stallingTracker.postCommitUnlockedEntryLock + stallingTracker.postCommitUnlockedReleaseLock <- struct{}{} + }() + + // issue a LookupWithoutRewards while persistedData.round != au.cachedDBRound + // when synchronized=false it will fail fast + d, validThrough, err := au.lookupWithoutRewards(rnd, addr, false) + require.Equal(t, err, &MismatchingDatabaseRoundError{databaseRound: 2, memoryRound: 1}) + + // release the postCommit lock, once au.lookupWithoutRewards() hits au.accountsReadCond.Wait() go func() { time.Sleep(200 * time.Millisecond) stallingTracker.postCommitReleaseLock <- struct{}{} }() - // issue a LookupWithoutRewards while persistedData.round != au.cachedDBRound - d, validThrough, err := au.LookupWithoutRewards(rnd, addr) + // when synchronized=true it will wait until above goroutine releases postCommitReleaseLock + d, validThrough, err = au.lookupWithoutRewards(rnd, addr, true) require.NoError(t, err) require.Equal(t, d, data) require.GreaterOrEqualf(t, uint64(validThrough), uint64(rnd), "validThrough: %v rnd :%v", validThrough, rnd) - - // allow the postCommitUnlocked() handler to go through - <-stallingTracker.postCommitUnlockedEntryLock - stallingTracker.postCommitUnlockedReleaseLock <- struct{}{} } -- cgit v1.2.3