lessexecutor_test.go 643 B

1234567891011121314151617181920212223242526
  1. package executors
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tal-tech/go-zero/core/timex"
  7. )
  8. func TestLessExecutor_DoOrDiscard(t *testing.T) {
  9. executor := NewLessExecutor(time.Minute)
  10. assert.True(t, executor.DoOrDiscard(func() {}))
  11. assert.False(t, executor.DoOrDiscard(func() {}))
  12. executor.lastTime.Set(timex.Now() - time.Minute - time.Second*30)
  13. assert.True(t, executor.DoOrDiscard(func() {}))
  14. assert.False(t, executor.DoOrDiscard(func() {}))
  15. }
  16. func BenchmarkLessExecutor(b *testing.B) {
  17. exec := NewLessExecutor(time.Millisecond)
  18. for i := 0; i < b.N; i++ {
  19. exec.DoOrDiscard(func() {
  20. })
  21. }
  22. }