Skip to content

Commit

Permalink
testing: fix random data race in TestAppAccountDataStorage (#3315)
Browse files Browse the repository at this point in the history
fix random data race in unit test
  • Loading branch information
tsachiherman authored Dec 15, 2021
1 parent 34e2fbd commit de7fe45
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ledger/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de7fe45

Please sign in to comment.