forked from benalexau/ibconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier_test.go
58 lines (51 loc) · 1.05 KB
/
notifier_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package core
import (
"testing"
"time"
)
func TestNotifications(t *testing.T) {
config := NewTestConfig(t)
notifier, err := NewNotifier(config.DbUrl)
if err != nil {
t.Fatal(err)
}
defer notifier.Close()
var ntPlay NtType = "plaything"
err = notifier.RegisterAll([]NtType{ntPlay})
if err != nil {
t.Fatal(err)
}
nc1 := make(chan *Notification)
nc2 := make(chan *Notification)
notifier.Subscribe(nc1)
notifier.Subscribe(nc2)
defer notifier.Unsubscribe(nc1)
defer notifier.Unsubscribe(nc2)
payload := int64(4340986482)
go func() {
notifier.Publish(ntPlay, payload)
}()
received := 0
for {
select {
case msg := <-nc1:
received++
if msg.Id != payload || msg.Type != ntPlay {
t.Fatalf("Incorrect payload")
}
if received == 2 {
return
}
case msg := <-nc2:
received++
if msg.Id != payload || msg.Type != ntPlay {
t.Fatalf("Incorrect payload")
}
if received == 2 {
return
}
case <-time.After(3000 * time.Millisecond):
t.Fatalf("Did not receive 2 notifications (received %d)", received)
}
}
}