aboutsummaryrefslogtreecommitdiffstats
path: root/event
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-11-05 19:16:27 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-11-05 22:55:53 +0800
commit8e2bf42c46b8dc7d13f976c7b004001cc3d1089a (patch)
tree1fac2bd6b95485d86d01a974316fb78681f602b7 /event
parente3f36d97288636f222f451b26c7c89e334ce4869 (diff)
downloadgo-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar.gz
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar.bz2
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar.lz
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar.xz
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.tar.zst
go-tangerine-8e2bf42c46b8dc7d13f976c7b004001cc3d1089a.zip
event/filter: fix data race in the test
Diffstat (limited to 'event')
-rw-r--r--event/filter/filter_test.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/event/filter/filter_test.go b/event/filter/filter_test.go
index 0cd26bfc9..dcc911245 100644
--- a/event/filter/filter_test.go
+++ b/event/filter/filter_test.go
@@ -21,35 +21,40 @@ import (
"time"
)
+// Simple test to check if baseline matching/mismatching filtering works.
func TestFilters(t *testing.T) {
- var success bool
- var failure bool
-
fm := New()
fm.Start()
+
+ // Register two filters to catch posted data
+ first := make(chan struct{})
fm.Install(Generic{
Str1: "hello",
Fn: func(data interface{}) {
- success = data.(bool)
+ first <- struct{}{}
},
})
+ second := make(chan struct{})
fm.Install(Generic{
Str1: "hello1",
Str2: "hello",
Fn: func(data interface{}) {
- failure = true
+ second <- struct{}{}
},
})
+ // Post an event that should only match the first filter
fm.Notify(Generic{Str1: "hello"}, true)
fm.Stop()
- time.Sleep(10 * time.Millisecond) // yield to the notifier
-
- if !success {
- t.Error("expected 'hello' to be posted")
+ // Ensure only the mathcing filters fire
+ select {
+ case <-first:
+ case <-time.After(100 * time.Millisecond):
+ t.Error("matching filter timed out")
}
-
- if failure {
- t.Error("hello1 was triggered")
+ select {
+ case <-second:
+ t.Error("mismatching filter fired")
+ case <-time.After(100 * time.Millisecond):
}
}