From de7fe4538af68a18d1a4963be1ea6b932649f579 Mon Sep 17 00:00:00 2001 From: Tsachi Herman Date: Wed, 15 Dec 2021 12:14:38 -0500 Subject: [PATCH] testing: fix random data race in TestAppAccountDataStorage (#3315) fix random data race in unit test --- ledger/applications_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ledger/applications_test.go b/ledger/applications_test.go index 43a03bfb7c..5630fc19c4 100644 --- a/ledger/applications_test.go +++ b/ledger/applications_test.go @@ -39,7 +39,18 @@ func commitRound(offset uint64, dbRound basics.Round, l *Ledger) { l.trackers.mu.Unlock() l.trackers.scheduleCommit(l.Latest(), l.Latest()-(dbRound+basics.Round(offset))) - l.trackers.waitAccountsWriting() + // wait for the operation to complete. Once it does complete, the tr.lastFlushTime is going to be updated, so we can + // use that as an indicator. + for { + l.trackers.mu.Lock() + isDone := (!l.trackers.lastFlushTime.IsZero()) && (len(l.trackers.deferredCommits) == 0) + l.trackers.mu.Unlock() + if isDone { + break + } + time.Sleep(time.Millisecond) + + } } // test ensures that