forked from mdlayher/vsock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_linux_gteq_1.11_test.go
63 lines (49 loc) · 1.21 KB
/
integration_linux_gteq_1.11_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
//+build go1.11,linux
package vsock_test
import (
"net"
"strings"
"sync"
"testing"
"time"
"github.com/mdlayher/vsock/internal/vsutil"
)
func TestIntegrationListenerUnblockAcceptAfterClose(t *testing.T) {
l, done := newListener(t)
defer done()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
t.Log("start accept")
_, err := vsutil.Accept(l, 10*time.Second)
t.Log("after accept")
nerr, ok := err.(*net.OpError)
if !ok {
t.Errorf("expected a net.OpError, but got: %#v", err)
}
if nerr.Temporary() {
t.Errorf("expected permanent error, but got temporary one: %v", err)
}
// We mimic what net.TCPConn does and return an error with the same
// string as internal/poll, so string matching is the best we can do
// for now.
if !strings.Contains(nerr.Err.Error(), "use of closed") {
t.Errorf("expected close network connection error, but got: %v", nerr.Err)
}
}()
time.Sleep(100 * time.Millisecond)
if err := l.Close(); err != nil {
t.Fatalf("failed to close listener: %v", err)
}
doneC := make(chan struct{})
go func() {
wg.Wait()
close(doneC)
}()
select {
case <-doneC:
case <-time.After(5 * time.Second):
t.Fatal("timeout waiting accept to unblock")
}
}