delta time.Duration // for deadline
guard time.Duration
- max time.Duration
}{
// Tests that dial timeouts, deadlines in the past work.
- {-5 * time.Second, 0, -5 * time.Second, 100 * time.Millisecond},
- {0, -5 * time.Second, -5 * time.Second, 100 * time.Millisecond},
- {-5 * time.Second, 5 * time.Second, -5 * time.Second, 100 * time.Millisecond}, // timeout over deadline
- {-1 << 63, 0, time.Second, 100 * time.Millisecond},
- {0, -1 << 63, time.Second, 100 * time.Millisecond},
-
- {50 * time.Millisecond, 0, 100 * time.Millisecond, time.Second},
- {0, 50 * time.Millisecond, 100 * time.Millisecond, time.Second},
- {50 * time.Millisecond, 5 * time.Second, 100 * time.Millisecond, time.Second}, // timeout over deadline
+ {-5 * time.Second, 0, -5 * time.Second},
+ {0, -5 * time.Second, -5 * time.Second},
+ {-5 * time.Second, 5 * time.Second, -5 * time.Second}, // timeout over deadline
+ {-1 << 63, 0, time.Second},
+ {0, -1 << 63, time.Second},
+
+ {50 * time.Millisecond, 0, 100 * time.Millisecond},
+ {0, 50 * time.Millisecond, 100 * time.Millisecond},
+ {50 * time.Millisecond, 5 * time.Second, 100 * time.Millisecond}, // timeout over deadline
}
func TestDialTimeout(t *testing.T) {
})
}
- ch := make(chan error)
d := Dialer{Timeout: tt.timeout}
if tt.delta != 0 {
d.Deadline = time.Now().Add(tt.delta)
}
- max := time.NewTimer(tt.max)
- defer max.Stop()
- go func() {
- // This dial never starts to send any TCP SYN
- // segment because of above socket filter and
- // test hook.
- c, err := d.Dial("tcp", "127.0.0.1:0")
- if err == nil {
- err = fmt.Errorf("unexpectedly established: tcp:%s->%s", c.LocalAddr(), c.RemoteAddr())
- 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.Errorf("#%d: %v", i, perr)
- }
- if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
- t.Fatalf("#%d: %v", i, err)
- }
+ // This dial never starts to send any TCP SYN
+ // segment because of above socket filter and
+ // test hook.
+ c, err := d.Dial("tcp", "127.0.0.1:0")
+ if err == nil {
+ err = fmt.Errorf("unexpectedly established: tcp:%s->%s", c.LocalAddr(), c.RemoteAddr())
+ c.Close()
+ }
+
+ if perr := parseDialError(err); perr != nil {
+ t.Errorf("#%d: %v", i, perr)
+ }
+ if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
+ t.Fatalf("#%d: %v", i, err)
}
}
}