-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpair_test.go
49 lines (42 loc) · 982 Bytes
/
pair_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
package zeroless
import "testing"
func checkExchangedData(t *testing.T, received []string, expected []string) {
for i, _ := range received {
if received[i] != expected[i] {
t.Error("Received:", received, "Expected:", expected)
}
}
}
func TestDoublePingThenPong(t *testing.T) {
pairReceiver, _ := NewServer(1054).Pair()
client := NewClient()
client.ConnectLocal(1054)
pairSender, _ := client.Pair()
pings := [][]string{
[]string{"ping1"},
[]string{"ping2"},
[]string{"ping11", "ping12"},
[]string{"ping21", "ping22"},
}
pongs := [][]string{
[]string{"pong1"},
[]string{"pong2"},
[]string{"pong11", "ping12"},
[]string{"pong21", "pong22"},
}
for i, ping := range pings {
pairSender <- ping
pairSender <- ping
y := 0
for result := range pairReceiver {
checkExchangedData(t, result, ping)
y += 1
if y == 2 {
pairReceiver <- pongs[i]
break
}
}
result := <-pairSender
checkExchangedData(t, result, pongs[i])
}
}