Skip to content

Commit

Permalink
test: fix race in test introduced in #44
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Oct 8, 2022
1 parent 79f9aa2 commit a84e0fc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions timer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clockwork

import (
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -141,10 +142,15 @@ func TestFakeClockTimer_ResetRace(t *testing.T) {
var times []time.Time
timer := fc.NewTimer(d)
done := make(chan struct{})
var wg sync.WaitGroup

wg.Add(1)

go func() {
for {
select {
case <-done:
wg.Done()
break
case now := <-timer.Chan():
times = append(times, now)
Expand All @@ -159,6 +165,7 @@ func TestFakeClockTimer_ResetRace(t *testing.T) {
}
timer.Stop()
close(done)
wg.Wait()
for i := 1; i < len(times); i++ {
if times[i-1] == times[i] {
t.Fatalf("Timer repeatedly reported the same time.")
Expand Down

0 comments on commit a84e0fc

Please sign in to comment.