fanout_test.go 554 B

123456789101112131415161718192021222324252627282930
  1. package fanout
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. )
  7. func TestFanout_Do(t *testing.T) {
  8. ca := New("cache", Worker(1), Buffer(1024))
  9. var run bool
  10. ca.Do(context.Background(), func(c context.Context) {
  11. run = true
  12. panic("error")
  13. })
  14. time.Sleep(time.Millisecond * 50)
  15. t.Log("not panic")
  16. if !run {
  17. t.Fatal("expect run be true")
  18. }
  19. }
  20. func TestFanout_Close(t *testing.T) {
  21. ca := New("cache", Worker(1), Buffer(1024))
  22. ca.Close()
  23. err := ca.Do(context.Background(), func(c context.Context) {})
  24. if err == nil {
  25. t.Fatal("expect get err")
  26. }
  27. }