audio: Improve test flakiness

This commit is contained in:
Hajime Hoshi 2018-12-27 03:34:27 +09:00
parent 25581b2be8
commit ed7552962d

View File

@ -70,11 +70,21 @@ func TestGC(t *testing.T) {
runtime.KeepAlive(p) runtime.KeepAlive(p)
p = nil p = nil
runtime.GC() runtime.GC()
// 100[ms] should be enough all the bytes are consumed.
// TODO: This is a darty hack. Would it be possible to use virtual time? ch := make(chan struct{})
time.Sleep(100 * time.Millisecond) go func() {
got = PlayersNumForTesting() defer close(ch)
if want := 0; got != want { for i := 0; i < 10; i++ {
t.Errorf("PlayersNum() after GC: got: %d, want: %d", got, want) got = PlayersNumForTesting()
} if want := 0; got == want {
return
}
// 100[ms] should be enough all the bytes are consumed.
// TODO: This is a darty hack. Would it be possible to use virtual time?
time.Sleep(100 * time.Millisecond)
}
t.Errorf("time out")
}()
<-ch
} }