File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -21,35 +21,40 @@ import (
21
21
"time"
22
22
)
23
23
24
+ // Simple test to check if baseline matching/mismatching filtering works.
24
25
func TestFilters (t * testing.T ) {
25
- var success bool
26
- var failure bool
27
-
28
26
fm := New ()
29
27
fm .Start ()
28
+
29
+ // Register two filters to catch posted data
30
+ first := make (chan struct {})
30
31
fm .Install (Generic {
31
32
Str1 : "hello" ,
32
33
Fn : func (data interface {}) {
33
- success = data .( bool )
34
+ first <- struct {}{}
34
35
},
35
36
})
37
+ second := make (chan struct {})
36
38
fm .Install (Generic {
37
39
Str1 : "hello1" ,
38
40
Str2 : "hello" ,
39
41
Fn : func (data interface {}) {
40
- failure = true
42
+ second <- struct {}{}
41
43
},
42
44
})
45
+ // Post an event that should only match the first filter
43
46
fm .Notify (Generic {Str1 : "hello" }, true )
44
47
fm .Stop ()
45
48
46
- time .Sleep (10 * time .Millisecond ) // yield to the notifier
47
-
48
- if ! success {
49
- t .Error ("expected 'hello' to be posted" )
49
+ // Ensure only the mathcing filters fire
50
+ select {
51
+ case <- first :
52
+ case <- time .After (100 * time .Millisecond ):
53
+ t .Error ("matching filter timed out" )
50
54
}
51
-
52
- if failure {
53
- t .Error ("hello1 was triggered" )
55
+ select {
56
+ case <- second :
57
+ t .Error ("mismatching filter fired" )
58
+ case <- time .After (100 * time .Millisecond ):
54
59
}
55
60
}
You can’t perform that action at this time.
0 commit comments