watcher_test.go 737 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package store
  2. import (
  3. "testing"
  4. )
  5. func TestWatcher(t *testing.T) {
  6. s := New()
  7. wh := s.WatcherHub
  8. c, err := wh.watch("/foo", true, 1)
  9. if err != nil {
  10. t.Fatal("%v", err)
  11. }
  12. select {
  13. case <-c:
  14. t.Fatal("should not receive from channel before send the event")
  15. default:
  16. // do nothing
  17. }
  18. e := newEvent(Create, "/foo/bar", 1, 1)
  19. wh.notify(e)
  20. re := <-c
  21. if e != re {
  22. t.Fatal("recv != send")
  23. }
  24. c, _ = wh.watch("/foo", false, 2)
  25. e = newEvent(Create, "/foo/bar", 2, 1)
  26. wh.notify(e)
  27. select {
  28. case re = <-c:
  29. t.Fatal("should not receive from channel if not recursive ", re)
  30. default:
  31. // do nothing
  32. }
  33. e = newEvent(Create, "/foo", 3, 1)
  34. wh.notify(e)
  35. re = <-c
  36. if e != re {
  37. t.Fatal("recv != send")
  38. }
  39. }