aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-12-14 17:07:24 -0500
committerBryan Mills <bcmills@google.com>2021-12-15 13:31:58 +0000
commitb5c0dbaafc548bd432c14935ae242ce1433180e8 (patch)
tree0c7b4317136fbd002d0f10b44b2baf385fd4b8dd /src/net
parent9d0ca262bbfa5561910f75e7b7d937b615d69393 (diff)
downloadgo-b5c0dbaafc548bd432c14935ae242ce1433180e8.tar.gz
go-b5c0dbaafc548bd432c14935ae242ce1433180e8.zip
net: eliminate arbitrary timeout in TestVariousDeadlines
When we set a timeout, we don't actually have a guarantee one how long the OS will take to notice it. Moreover, if the test deadlocks completely (for example, due to a deadline never taking effect), it would be more useful to get a full goroutine dump instead of the current "client stuck in Dial+Copy" failure message. For #37883 For #41863 Change-Id: I9f712ef1c620f97a5ab69baac45deb71134b99bc Reviewed-on: https://go-review.googlesource.com/c/go/+/371994 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/timeout_test.go34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go
index 032770dd83..3c6aa27cc1 100644
--- a/src/net/timeout_test.go
+++ b/src/net/timeout_test.go
@@ -947,35 +947,23 @@ func testVariousDeadlines(t *testing.T) {
name := fmt.Sprintf("%v %d/%d", timeout, run, numRuns)
t.Log(name)
- tooSlow := time.NewTimer(5 * time.Second)
- defer tooSlow.Stop()
-
c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
- ch := make(chan result, 1)
- go func() {
- t0 := time.Now()
- if err := c.SetDeadline(t0.Add(timeout)); err != nil {
- t.Error(err)
- }
- n, err := io.Copy(io.Discard, c)
- dt := time.Since(t0)
- c.Close()
- ch <- result{n, err, dt}
- }()
+ t0 := time.Now()
+ if err := c.SetDeadline(t0.Add(timeout)); err != nil {
+ t.Error(err)
+ }
+ n, err := io.Copy(io.Discard, c)
+ dt := time.Since(t0)
+ c.Close()
- select {
- case res := <-ch:
- if nerr, ok := res.err.(Error); ok && nerr.Timeout() {
- t.Logf("%v: good timeout after %v; %d bytes", name, res.d, res.n)
- } else {
- t.Fatalf("%v: Copy = %d, %v; want timeout", name, res.n, res.err)
- }
- case <-tooSlow.C:
- t.Fatalf("%v: client stuck in Dial+Copy", name)
+ if nerr, ok := err.(Error); ok && nerr.Timeout() {
+ t.Logf("%v: good timeout after %v; %d bytes", name, dt, n)
+ } else {
+ t.Fatalf("%v: Copy = %d, %v; want timeout", name, n, err)
}
}
}