summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Lehtonen <lars.lehtonen@gmail.com>2019-11-08 21:55:54 +0000
committerIan Lance Taylor <iant@golang.org>2019-11-08 22:12:41 +0000
commit9aaf51ad5c5ce7cc31d4cf386f4ab5bff37e9d3c (patch)
treed7aeb1b6bb9cbc233ca032c5f17b223c2600276a
parent380dde419d290c41960e262a7fbcbc059d70c4e3 (diff)
downloadnet-9aaf51ad5c5ce7cc31d4cf386f4ab5bff37e9d3c.tar.xz
netutil: fix test to not t.Fatal from goroutine
Change-Id: I07941ecadf7d7268542d13b402436b6111772d02 GitHub-Last-Rev: aece213e5011c6f1d6bbb10f8923adf25fdea2a0 GitHub-Pull-Request: golang/net#57 Reviewed-on: https://go-review.googlesource.com/c/net/+/203877 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
-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")
}
}