Skip to content

Commit 3e44db8

Browse files
authored
chore: fix flaky client initialization test (#742)
This commit retries the dialer a few times to handle the case where a client has connected but has not yet dialed the remote instance, while the test has already asserted the dialer should have run. Fixes #551
1 parent 8ce3469 commit 3e44db8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/proxy/proxy_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,19 @@ func TestClientLimitsMaxConnections(t *testing.T) {
342342
// it doesn't matter which is closed
343343
wantEOF(t, conn1, conn2)
344344

345-
want := 1
346-
if got := d.dialAttempts(); got != want {
345+
tryDialAttempts := func(t *testing.T, want int) {
346+
var got int
347+
for i := 0; i < 10; i++ {
348+
got = d.dialAttempts()
349+
if got == want {
350+
return
351+
}
352+
time.Sleep(100 * time.Millisecond)
353+
}
347354
t.Fatalf("dial attempts did not match expected, want = %v, got = %v", want, got)
348355
}
356+
want := 1
357+
tryDialAttempts(t, want)
349358
}
350359

351360
func tryTCPDial(t *testing.T, addr string) net.Conn {

0 commit comments

Comments
 (0)