]> Cypherpunks repositories - gostls13.git/commitdiff
net: remove timeout in TestDialTimeoutMaxDuration
authorTamir Duberstein <tamird@google.com>
Tue, 12 Oct 2021 19:03:25 +0000 (15:03 -0400)
committerDamien Neil <dneil@google.com>
Wed, 13 Oct 2021 17:02:43 +0000 (17:02 +0000)
This test seems only to be testing that Dial does not time out
immediately as a result of integer overflow; the precise time taken to
connect is immaterial. Replace naked loop with sub-tests.

Fixes #43069.

Change-Id: Ib5e38a1d8cd191b74c2bc7c26bef57b180e16f68
Reviewed-on: https://go-review.googlesource.com/c/go/+/355390
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/timeout_test.go

index e1cf1467c36f00aca3bf254d9c0676a91398a173..6c8e9cf76ef0098de3b3eed799f246911526aa77 100644 (file)
@@ -93,53 +93,38 @@ func TestDialTimeout(t *testing.T) {
        }
 }
 
-var dialTimeoutMaxDurationTests = []struct {
-       timeout time.Duration
-       delta   time.Duration // for deadline
-}{
-       // Large timeouts that will overflow an int64 unix nanos.
-       {1<<63 - 1, 0},
-       {0, 1<<63 - 1},
-}
-
 func TestDialTimeoutMaxDuration(t *testing.T) {
-       if runtime.GOOS == "openbsd" {
-               testenv.SkipFlaky(t, 15157)
-       }
-
        ln, err := newLocalListener("tcp")
        if err != nil {
                t.Fatal(err)
        }
-       defer ln.Close()
+       defer func() {
+               if err := ln.Close(); err != nil {
+                       t.Error(err)
+               }
+       }()
 
-       for i, tt := range dialTimeoutMaxDurationTests {
-               ch := make(chan error)
-               max := time.NewTimer(250 * time.Millisecond)
-               defer max.Stop()
-               go func() {
+       for _, tt := range []struct {
+               timeout time.Duration
+               delta   time.Duration // for deadline
+       }{
+               // Large timeouts that will overflow an int64 unix nanos.
+               {1<<63 - 1, 0},
+               {0, 1<<63 - 1},
+       } {
+               t.Run(fmt.Sprintf("timeout=%s/delta=%s", tt.timeout, tt.delta), func(t *testing.T) {
                        d := Dialer{Timeout: tt.timeout}
                        if tt.delta != 0 {
                                d.Deadline = time.Now().Add(tt.delta)
                        }
                        c, err := d.Dial(ln.Addr().Network(), ln.Addr().String())
-                       if err == nil {
-                               c.Close()
-                       }
-                       ch <- err
-               }()
-
-               select {
-               case <-max.C:
-                       t.Fatalf("#%d: Dial didn't return in an expected time", i)
-               case err := <-ch:
-                       if perr := parseDialError(err); perr != nil {
-                               t.Error(perr)
-                       }
                        if err != nil {
-                               t.Errorf("#%d: %v", i, err)
+                               t.Fatal(err)
                        }
-               }
+                       if err := c.Close(); err != nil {
+                               t.Error(err)
+                       }
+               })
        }
 }