Skip to content

Commit

Permalink
tests: fix flaky ledger stateproof and rpcs tests (#5494)
Browse files Browse the repository at this point in the history
* TestLedgerSPTrackerAfterReplay and TestVotersReloadFromDiskPassRecoveryPeriod:
  got rid of calling a flusher that adds blocks on each flush. Sometimes it added too many blocks
  and the trackers state changed beyond the test expectation.
* TestRedirectOnFullCapacity flaked because crypto.RandUint64() % 100 gave the same value
  twice in a row.
  • Loading branch information
algorandskiy committed Jun 23, 2023
1 parent 91185ae commit f514d82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,16 @@ func testVotersReloadFromDiskPassRecoveryPeriod(t *testing.T, cfg config.Local)

// the voters tracker should contain all the voters for each stateproof round. nothing should be removed
l.WaitForCommit(l.Latest())
triggerTrackerFlush(t, l, genesisInitState)
// wait for any pending tracker flushes
l.trackers.waitAccountsWriting()
// force flush as needed
if l.LatestTrackerCommitted() < l.Latest()+basics.Round(cfg.MaxAcctLookback) {
l.trackers.mu.Lock()
l.trackers.lastFlushTime = time.Time{}
l.trackers.mu.Unlock()
l.notifyCommit(l.Latest())
l.trackers.waitAccountsWriting()
}

vtSnapshot := l.acctsOnline.voters.votersForRoundCache
beforeRemoveVotersLen := len(vtSnapshot)
Expand Down Expand Up @@ -3259,7 +3268,18 @@ func TestLedgerSPTrackerAfterReplay(t *testing.T) {
// To be deleted, but not yet deleted (waiting for commit)
verifyStateProofVerificationTracking(t, &l.spVerification, firstStateProofRound, 1, proto.StateProofInterval, true, any)

triggerTrackerFlush(t, l, genesisInitState)
// first ensure the block is committed into blockdb
l.WaitForCommit(l.Latest())
// wait for any pending tracker flushes
l.trackers.waitAccountsWriting()
// force flush as needed
if l.LatestTrackerCommitted() < l.Latest()+basics.Round(cfg.MaxAcctLookback) {
l.trackers.mu.Lock()
l.trackers.lastFlushTime = time.Time{}
l.trackers.mu.Unlock()
l.notifyCommit(spblk.BlockHeader.Round)
l.trackers.waitAccountsWriting()
}

err = l.reloadLedger()
a.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion rpcs/blockService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func addBlock(t *testing.T, ledger *data.Ledger) (timestamp int64) {
blk, err := ledger.Block(ledger.LastRound())
require.NoError(t, err)
blk.BlockHeader.Round++
blk.BlockHeader.TimeStamp += int64(crypto.RandUint64() % 100 * 1000)
blk.BlockHeader.TimeStamp += int64(crypto.RandUint64() % 100000 * 1000)
blk.TxnCommitments, err = blk.PaysetCommit()
require.NoError(t, err)

Expand Down

0 comments on commit f514d82

Please sign in to comment.