summaryrefslogtreecommitdiff
path: root/libgo/go/net/dial_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/dial_test.go')
-rw-r--r--libgo/go/net/dial_test.go39
1 files changed, 23 insertions, 16 deletions
diff --git a/libgo/go/net/dial_test.go b/libgo/go/net/dial_test.go
index 00a84d17d60..3a2c59a2d1d 100644
--- a/libgo/go/net/dial_test.go
+++ b/libgo/go/net/dial_test.go
@@ -318,9 +318,9 @@ func TestDialParallel(t *testing.T) {
expectElapsedMin := tt.expectElapsed - 95*time.Millisecond
expectElapsedMax := tt.expectElapsed + 95*time.Millisecond
- if !(elapsed >= expectElapsedMin) {
+ if elapsed < expectElapsedMin {
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectElapsedMin)
- } else if !(elapsed <= expectElapsedMax) {
+ } else if elapsed > expectElapsedMax {
t.Errorf("#%d: got %v; want <= %v", i, elapsed, expectElapsedMax)
}
@@ -346,7 +346,7 @@ func TestDialParallel(t *testing.T) {
}
}
-func lookupSlowFast(ctx context.Context, fn func(context.Context, string) ([]IPAddr, error), host string) ([]IPAddr, error) {
+func lookupSlowFast(ctx context.Context, fn func(context.Context, string, string) ([]IPAddr, error), network, host string) ([]IPAddr, error) {
switch host {
case "slow6loopback4":
// Returns a slow IPv6 address, and a local IPv4 address.
@@ -355,7 +355,7 @@ func lookupSlowFast(ctx context.Context, fn func(context.Context, string) ([]IPA
{IP: ParseIP("127.0.0.1")},
}, nil
default:
- return fn(ctx, host)
+ return fn(ctx, network, host)
}
}
@@ -418,10 +418,10 @@ func TestDialerFallbackDelay(t *testing.T) {
}
expectMin := tt.expectElapsed - 1*time.Millisecond
expectMax := tt.expectElapsed + 95*time.Millisecond
- if !(elapsed >= expectMin) {
+ if elapsed < expectMin {
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectMin)
}
- if !(elapsed <= expectMax) {
+ if elapsed > expectMax {
t.Errorf("#%d: got %v; want <= %v", i, elapsed, expectMax)
}
}
@@ -729,22 +729,29 @@ func TestDialerKeepAlive(t *testing.T) {
if err := ls.buildup(handler); err != nil {
t.Fatal(err)
}
- defer func() { testHookSetKeepAlive = func() {} }()
+ defer func() { testHookSetKeepAlive = func(time.Duration) {} }()
- for _, keepAlive := range []bool{false, true} {
- got := false
- testHookSetKeepAlive = func() { got = true }
- var d Dialer
- if keepAlive {
- d.KeepAlive = 30 * time.Second
- }
+ tests := []struct {
+ ka time.Duration
+ expected time.Duration
+ }{
+ {-1, -1},
+ {0, 15 * time.Second},
+ {5 * time.Second, 5 * time.Second},
+ {30 * time.Second, 30 * time.Second},
+ }
+
+ for _, test := range tests {
+ var got time.Duration = -1
+ testHookSetKeepAlive = func(d time.Duration) { got = d }
+ d := Dialer{KeepAlive: test.ka}
c, err := d.Dial("tcp", ls.Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
c.Close()
- if got != keepAlive {
- t.Errorf("Dialer.KeepAlive = %v: SetKeepAlive called = %v, want %v", d.KeepAlive, got, !got)
+ if got != test.expected {
+ t.Errorf("Dialer.KeepAlive = %v: SetKeepAlive set to %v, want %v", d.KeepAlive, got, test.expected)
}
}
}