Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: fix random data race in TestAppAccountDataStorage #3315

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should work, it's a little clearer since you wouldn't have to check for the uninitialized case:

Suggested change
isDone := (!l.trackers.lastFlushTime.IsZero()) && (len(l.trackers.deferredCommits) == 0)
isDone := l.trackers.dbRound == l.Latest()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dbRound is the round of the database, not the committed round number. The database is about 320 rounds behind.

l.trackers.mu.Unlock()
if isDone {
break
}
time.Sleep(time.Millisecond)

}
}

// test ensures that
Expand Down