-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
61 lines (49 loc) · 912 Bytes
/
server_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
package fastcall
import (
"bytes"
"sync"
"testing"
)
func TestServer(t *testing.T) {
serv, err := Serve("localhost:1337")
if err != nil {
t.Fatal(err)
} else {
defer serv.Close()
}
conn, err := Dial("localhost:1337")
if err != nil {
t.Fatal(err)
} else {
defer conn.Close()
}
var w sync.WaitGroup
w.Add(2)
go func() {
conn, err := serv.Accept()
if err != nil {
t.Fatal(err)
}
if msg, err := conn.Read(); err != nil {
t.Fatal(err)
} else if !bytes.Equal(msg, []byte{1, 2, 3, 4}) {
t.Fatal("wrong value")
}
if err := conn.Write([]byte{5, 6, 7, 8}); err != nil {
t.Fatal(err)
}
w.Done()
}()
go func() {
if err := conn.Write([]byte{1, 2, 3, 4}); err != nil {
t.Fatal(err)
}
if msg, err := conn.Read(); err != nil {
t.Fatal(err)
} else if !bytes.Equal(msg, []byte{5, 6, 7, 8}) {
t.Fatal("wrong value")
}
w.Done()
}()
w.Wait()
}