-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
54 lines (45 loc) · 933 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
package main
import (
"context"
"fmt"
"log"
"sync"
"testing"
"time"
"redos/client"
)
func TestServerWithManyClient(t *testing.T) {
server := NewServer(Config{})
go func() {
log.Fatal(server.start())
}()
time.Sleep(time.Second)
nClients := 10
wg := sync.WaitGroup{}
wg.Add(nClients)
for i := 0; i < nClients; i++ {
go func(it int) {
defer wg.Done()
c, err := client.NewClient("localhost:8888")
if err != nil {
log.Fatal(err)
}
defer c.Close()
key := fmt.Sprintf("client_foo_%d", it)
value := fmt.Sprintf("client_bar_%d", it)
if err := c.Set(context.TODO(), key, value); err != nil {
log.Fatal(err)
}
val, err := c.Get(context.TODO(), key)
if err != nil {
log.Fatal(err)
}
fmt.Println("client got this value :", val)
}(i)
}
wg.Wait()
time.Sleep(time.Second)
if len(server.peers) != 0 {
log.Fatalf("%d peers in peer pool\n", len(server.peers))
}
}