-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpubsub_test.go
69 lines (58 loc) · 1.5 KB
/
pubsub_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
59
60
61
62
63
64
65
66
67
68
69
package zeroless
import (
"testing"
"time"
)
func TestPublish(t *testing.T) {
publisher, _ := NewServer(1025).Pub()
client := NewClient()
client.ConnectLocal(1025)
subscriber, _ := client.Sub()
msgs := [][]string{
[]string{"msg"},
[]string{"msg11", "msg12"},
[]string{"msg21", "msg22"},
}
time.Sleep(10 * time.Millisecond)
for _, msg := range msgs {
publisher <- msg
result := <-subscriber
checkExchangedData(t, result, msg)
}
}
func TestPublishWithTopic(t *testing.T) {
publisherWithTopic, _ := NewServer(1026).PubWithTopic("urgent", true)
client := NewClient()
client.ConnectLocal(1026)
subscriberWithTopics, _ := client.SubWithTopics([]string{"urgent"})
msgs := [][]string{
[]string{"msg"},
[]string{"msg11", "msg12"},
[]string{"msg21", "msg22"},
}
time.Sleep(10 * time.Millisecond)
for _, msg := range msgs {
publisherWithTopic <- msg
result := <-subscriberWithTopics
checkExchangedData(t, result, append([]string{"urgent"}, msg...))
}
}
func TestPublishWithManyTopics(t *testing.T) {
publisherWithoutTopic, _ := NewServer(1027).Pub()
client := NewClient()
client.ConnectLocal(1027)
subscriberWithManyTopics, _ := client.SubWithTopics([]string{"a", "c"})
msgs := [][]string{
[]string{"a", "msg"},
[]string{"b", "msg11", "msg12"},
[]string{"c", "msg21", "msg22"},
}
time.Sleep(10 * time.Millisecond)
for _, msg := range msgs {
publisherWithoutTopic <- msg
if msg[0] != "b" {
result := <-subscriberWithManyTopics
checkExchangedData(t, result, msg)
}
}
}