* fix bug #317.
* add counter for current task. If it's bigger then zero, do not quit background thread

* Revert "fix issue #317 (#331)"

This reverts commit fc43876cc5.
This commit is contained in:
weibobo
2021-01-02 18:04:04 +08:00
committed by GitHub
parent fc43876cc5
commit d643007c79
2 changed files with 26 additions and 39 deletions

View File

@@ -140,25 +140,6 @@ 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()
@@ -168,3 +149,11 @@ func BenchmarkExecutor(b *testing.B) {
executor.Add(1)
}
}
func TestPeriodicalExecutor_Deadlock(t *testing.T) {
executer := NewBulkExecutor(func(tasks []interface{}) {
}, WithBulkTasks(1), WithBulkInterval(time.Millisecond))
for i := 0; i < 1e6; i++ {
executer.Add(1)
}
}