delayexecutor_test.go 384 B

123456789101112131415161718192021
  1. package executors
  2. import (
  3. "sync/atomic"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestDelayExecutor(t *testing.T) {
  9. var count int32
  10. ex := NewDelayExecutor(func() {
  11. atomic.AddInt32(&count, 1)
  12. }, time.Millisecond*10)
  13. for i := 0; i < 100; i++ {
  14. ex.Trigger()
  15. }
  16. time.Sleep(time.Millisecond * 100)
  17. assert.Equal(t, int32(1), atomic.LoadInt32(&count))
  18. }