-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws_test.go
56 lines (50 loc) · 1.04 KB
/
ws_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
package katamari
import (
"net/url"
"os"
"sync"
"testing"
"time"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/require"
)
func TestWsTime(t *testing.T) {
t.Parallel()
var wg sync.WaitGroup
app := Server{}
app.Silence = true
app.Tick = 100 * time.Millisecond
app.Start("localhost:0")
defer app.Close(os.Interrupt)
u := url.URL{Scheme: "ws", Host: app.Address, Path: "/"}
c1, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
require.NoError(t, err)
c2, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
require.NoError(t, err)
wg.Add(3)
go func() {
for {
_, message, err := c1.ReadMessage()
if err != nil {
app.Console.Err("read c1", err)
break
}
app.Console.Log("time c1", string(message))
wg.Done()
}
}()
for {
_, message, err := c2.ReadMessage()
if err != nil {
app.Console.Err("read c2", err)
break
}
app.Console.Log("time c2", string(message))
err = c2.Close()
require.NoError(t, err)
wg.Done()
}
wg.Wait()
err = c1.Close()
require.NoError(t, err)
}