confirm addition after add called in periodical executor

This commit is contained in:
kevin
2020-08-14 11:50:01 +08:00
parent e7dd04701c
commit 9d9399ad10
2 changed files with 43 additions and 9 deletions

View File

@@ -120,6 +120,26 @@ func TestPeriodicalExecutor_Wait(t *testing.T) {
executer.Wait()
}
func TestPeriodicalExecutor_WaitFast(t *testing.T) {
const total = 3
var cnt int
var lock sync.Mutex
executer := NewBulkExecutor(func(tasks []interface{}) {
defer func() {
cnt++
}()
lock.Lock()
defer lock.Unlock()
time.Sleep(10 * time.Millisecond)
}, WithBulkTasks(1), WithBulkInterval(10*time.Millisecond))
for i := 0; i < total; i++ {
executer.Add(2)
}
executer.Flush()
executer.Wait()
assert.Equal(t, total, cnt)
}
// go test -benchtime 10s -bench .
func BenchmarkExecutor(b *testing.B) {
b.ReportAllocs()