-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_sketchy_test.go
58 lines (47 loc) · 1.3 KB
/
server_sketchy_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
// "Sketchy tests", i.e. targeted tests of edge conditions of the server.
// server_test.go is more for general "does it work well enough to pass"
// tests
package mp
import (
"sync"
"testing"
)
func TestServerBroadcastsToClientsWhenOneClientCloses(t *testing.T) {
serv, trans, conns := makeAuthedServerClientPairs("c1", "c2", "c3")
conns[2].Close()
defer shutdownAuthedServerClientPairs(serv, conns)
var wg sync.WaitGroup
recvCloseNotification := func(n int) {
defer wg.Done()
msg, err := trans[n].ReadMessage()
if err != nil {
t.Fatal("Error from client:", err)
}
if msg.Meta != MetaClientClosed {
t.Error("Expected message meta to be client closed, got", msg.Meta)
}
if msg.OtherClient != "c3" {
t.Error("Expected other client to be c3, but was", msg.OtherClient)
}
}
wg.Add(2)
for i := 0; i < 2; i++ {
go recvCloseNotification(i)
}
wg.Wait()
}
func TestServerClientReportsNoConnectionOnInvalidTarget(t *testing.T) {
serv, trans, conns := makeAuthedServerClientPairs("c1", "c2", "c3")
defer shutdownAuthedServerClientPairs(serv, conns)
msg := &Message{
OtherClient: "DNE",
}
trans[0].WriteMessage(msg)
msg, err := trans[0].ReadMessage()
if err != nil {
t.Fatal(err)
}
if msg.Meta != MetaNoSuchConnection {
t.Error("Expected no such connection complaint.")
}
}