-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient_test.go
69 lines (62 loc) · 1.13 KB
/
client_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 main
import (
"fmt"
"net"
"sync"
"testing"
"time"
)
func TestClient(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:8088")
if err != nil {
panic(err)
}
conn.Write([]byte("hello"))
data := make([]byte, 100)
n, err := conn.Read(data)
if err != nil {
panic(err)
}
fmt.Println(string(data[:n]))
time.Sleep(100 * time.Millisecond)
conn.Close()
}
func TestClients(t *testing.T) {
for i := 0; i < 100; i++ {
conn, err := net.Dial("tcp", "127.0.0.1:8088")
if err != nil {
panic(err)
}
conn.Write([]byte("hello"))
data := make([]byte, 100)
n, err := conn.Read(data)
if err != nil {
panic(err)
}
fmt.Println(string(data[:n]))
conn.Close()
}
}
func TestClientMulit(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
conn, err := net.Dial("tcp", "127.0.0.1:8088")
if err != nil {
panic(err)
}
conn.Write([]byte("hello"))
data := make([]byte, 100)
n, err := conn.Read(data)
if err != nil {
panic(err)
}
fmt.Println(string(data[:n]))
time.Sleep(100 * time.Millisecond)
conn.Close()
wg.Done()
}()
}
wg.Wait()
}