-
Notifications
You must be signed in to change notification settings - Fork 57
/
zmq4_timeout_test.go
49 lines (42 loc) · 1.13 KB
/
zmq4_timeout_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
// Copyright 2023 The go-zeromq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zmq4
import (
"context"
"testing"
"time"
)
func TestPushTimeout(t *testing.T) {
ep := "ipc://@push_timeout_test"
push := NewPush(context.Background(), WithTimeout(1*time.Second))
defer push.Close()
if err := push.Listen(ep); err != nil {
t.FailNow()
}
pull := NewPull(context.Background())
defer pull.Close()
if err := pull.Dial(ep); err != nil {
t.FailNow()
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for {
select {
case <-ctx.Done():
// The ctx limits overall time of execution
// If it gets canceled, that meain tests failed
// as write to socket did not genereate timeout error
t.Fatalf("test failed before being able to generate timeout error: %+v", ctx.Err())
default:
}
err := push.Send(NewMsgString("test string"))
if err == nil {
continue
}
if err != context.DeadlineExceeded {
t.Fatalf("expected a context.DeadlineExceeded error, got=%+v", err)
}
break
}
}