-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventbroker_test.go
52 lines (39 loc) · 1.06 KB
/
eventbroker_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
package sse
import (
"runtime"
"testing"
)
func TestBroker(t *testing.T) {
b := NewBroker()
b.Start()
streamOne, errOne := NewTestStream(true)
if errOne != nil {
t.Fatalf("Failed to instantiate test stream one")
}
streamTwo, errTwo := NewTestStream(true)
if errTwo != nil {
t.Fatalf("Failed to instantiate test stream two")
}
b.Subscribe(streamOne.EventStream())
b.Subscribe(streamTwo.EventStream())
e1 := BasicEvent{id: "1", data: "dataone"}
b.SendEvent(e1)
b.Unsubscribe(streamOne.EventStream())
e2 := BasicEvent{id: "2", data: "datatwo"}
b.SendEvent(e2)
b.Stop()
// I am upset that I have resorted to this
// need to let the other go routines run
// so that the events can be received by
// the streams
runtime.Gosched()
if !streamOne.Received(e1) {
t.Errorf("streamOne(%p) failed to receive e1", streamOne.EventStream())
}
if !streamTwo.Received(e1) {
t.Errorf("streamTwo(%p) failed to receive e1", streamTwo.EventStream())
}
if !streamTwo.Received(e2) {
t.Errorf("streamTwo(%p) failed to receive e2", streamTwo.EventStream())
}
}