-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendqueue_test.go
More file actions
47 lines (42 loc) · 826 Bytes
/
sendqueue_test.go
File metadata and controls
47 lines (42 loc) · 826 Bytes
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
package zsocket
import (
"context"
"fmt"
"sync"
"testing"
"time"
)
func TestSendQueueConcurrent(t *testing.T) {
client, server := testPair(t)
client.EnableSendQueue(32)
const n = 100
errCh := make(chan error, 1)
go func() {
for i := 0; i < n; i++ {
_, msg, err := server.Read(context.Background())
if err != nil {
errCh <- err
return
}
if len(msg) == 0 {
errCh <- fmt.Errorf("empty message")
return
}
}
errCh <- nil
}()
var wg sync.WaitGroup
for i := 0; i < n; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_ = client.Send(ctx, TextMessage, []byte(fmt.Sprintf("m-%d", i)))
}(i)
}
wg.Wait()
if err := <-errCh; err != nil {
t.Fatalf("server read: %v", err)
}
}