This commit is contained in:
Kevin Wan
2021-01-01 13:24:28 +08:00
committed by GitHub
parent a926cb514f
commit fc43876cc5
2 changed files with 36 additions and 2 deletions

View File

@@ -140,6 +140,25 @@ func TestPeriodicalExecutor_WaitFast(t *testing.T) {
assert.Equal(t, total, cnt)
}
func TestPeriodicalExecutor_Deadlock(t *testing.T) {
ticker := timex.NewFakeTicker()
defer ticker.Stop()
exec := NewPeriodicalExecutor(time.Millisecond, newContainer(time.Millisecond, nil))
exec.newTicker = func(d time.Duration) timex.Ticker {
return ticker
}
ticker.Tick()
exec.lock.Lock()
exec.backgroundFlush()
time.Sleep(20 * time.Millisecond)
ticker.Tick()
exec.commander <- 1
exec.lock.Unlock()
<-exec.confirmChan
exec.Wait()
}
// go test -benchtime 10s -bench .
func BenchmarkExecutor(b *testing.B) {
b.ReportAllocs()