summaryrefslogtreecommitdiff
path: root/netutil/listen_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'netutil/listen_test.go')
-rw-r--r--netutil/listen_test.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/netutil/listen_test.go b/netutil/listen_test.go
index e00433d..e77e6f4 100644
--- a/netutil/listen_test.go
+++ b/netutil/listen_test.go
@@ -18,6 +18,7 @@ import (
)
const defaultMaxOpenFiles = 256
+const timeout = 5 * time.Second
func TestLimitListener(t *testing.T) {
const max = 5
@@ -95,7 +96,7 @@ func TestLimitListenerError(t *testing.T) {
}()
select {
case <-donec:
- case <-time.After(5 * time.Second):
+ case <-time.After(timeout):
t.Fatal("timeout. deadlock?")
}
}
@@ -108,15 +109,15 @@ func TestLimitListenerClose(t *testing.T) {
defer ln.Close()
ln = LimitListener(ln, 1)
- doneCh := make(chan struct{})
- defer close(doneCh)
+ errCh := make(chan error)
go func() {
- c, err := net.Dial("tcp", ln.Addr().String())
+ defer close(errCh)
+ c, err := net.DialTimeout("tcp", ln.Addr().String(), timeout)
if err != nil {
- t.Fatal(err)
+ errCh <- err
+ return
}
- defer c.Close()
- <-doneCh
+ c.Close()
}()
c, err := ln.Accept()
@@ -125,6 +126,11 @@ func TestLimitListenerClose(t *testing.T) {
}
defer c.Close()
+ err = <-errCh
+ if err != nil {
+ t.Fatalf("DialTimeout: %v", err)
+ }
+
acceptDone := make(chan struct{})
go func() {
c, err := ln.Accept()
@@ -141,7 +147,7 @@ func TestLimitListenerClose(t *testing.T) {
select {
case <-acceptDone:
- case <-time.After(5 * time.Second):
+ case <-time.After(timeout):
t.Fatalf("Accept() still blocking")
}
}