...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v2store
16
17 import "testing"
18
19 func TestWatcher(t *testing.T) {
20 s := newStore()
21 wh := s.WatcherHub
22 w, err := wh.watch("/foo", true, false, 1, 1)
23 if err != nil {
24 t.Fatalf("%v", err)
25 }
26 c := w.EventChan()
27
28 select {
29 case <-c:
30 t.Fatal("should not receive from channel before send the event")
31 default:
32
33 }
34
35 e := newEvent(Create, "/foo/bar", 1, 1)
36
37 wh.notify(e)
38
39 re := <-c
40
41 if e != re {
42 t.Fatal("recv != send")
43 }
44
45 w, _ = wh.watch("/foo", false, false, 2, 1)
46 c = w.EventChan()
47
48 e = newEvent(Create, "/foo/bar", 2, 2)
49
50 wh.notify(e)
51
52 select {
53 case re = <-c:
54 t.Fatal("should not receive from channel if not recursive ", re)
55 default:
56
57 }
58
59 e = newEvent(Create, "/foo", 3, 3)
60
61 wh.notify(e)
62
63 re = <-c
64
65 if e != re {
66 t.Fatal("recv != send")
67 }
68
69
70 w, _ = wh.watch("/fo", true, false, 1, 1)
71 c = w.EventChan()
72
73 select {
74 case re = <-c:
75 t.Fatal("should not receive from channel:", re)
76 default:
77
78 }
79
80 e = newEvent(Create, "/fo/bar", 3, 3)
81
82 wh.notify(e)
83
84 re = <-c
85
86 if e != re {
87 t.Fatal("recv != send")
88 }
89
90 }
91
View as plain text