Fix activity log fragment race test (#11565)

* grab reference to done channel while locked

* add clarifying comment

* lock and grab channel reference again for test races
This commit is contained in:
swayne275 2021-05-07 17:02:11 -06:00 committed by GitHub
parent 91ed71c296
commit ee53fc5afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1125,9 +1125,14 @@ func (a *ActivityLog) activeFragmentWorker() {
}
}
// we modify the doneCh in some tests, so let's make sure we don't trip
// the race detector
a.l.RLock()
doneCh := a.doneCh
a.l.RUnlock()
for {
select {
case <-a.doneCh:
case <-doneCh:
// Shutting down activity log.
ticker.Stop()
return
@ -1707,9 +1712,12 @@ func (a *ActivityLog) retentionWorker(currentTime time.Time, retentionMonths int
// Cancel the context if activity log is shut down.
// This will cause the next storage operation to fail.
a.l.RLock()
doneCh := a.doneCh
a.l.RUnlock()
go func() {
select {
case <-a.doneCh:
case <-doneCh:
cancel()
case <-ctx.Done():
break

View File

@ -1386,7 +1386,9 @@ func TestActivityLog_refreshFromStoredLogWithBackgroundLoadingCancelled(t *testi
var wg sync.WaitGroup
close(a.doneCh)
defer func() {
a.l.Lock()
a.doneCh = make(chan struct{}, 1)
a.l.Unlock()
}()
err := a.refreshFromStoredLog(context.Background(), &wg, time.Now().UTC())