Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16e9b1e

Browse files
authored
fix: Add timeouts to every tailnet ping (#4986)
A ping isn't guaranteed to deliver, so these need to have a tight timeout for tests to not flake.
1 parent 45f81a7 commit 16e9b1e

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

agent/agent_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ func TestAgent(t *testing.T) {
499499

500500
conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0)
501501
require.Eventually(t, func() bool {
502-
_, err := conn.Ping(context.Background())
502+
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.IntervalFast)
503+
defer cancelFunc()
504+
_, err := conn.Ping(ctx)
503505
return err == nil
504506
}, testutil.WaitMedium, testutil.IntervalFast)
505507
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())

agent/apphealth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"sync"
77
"time"
88

9-
"golang.org/x/xerrors"
109
"github.com/google/uuid"
10+
"golang.org/x/xerrors"
1111

1212
"cdr.dev/slog"
1313
"github.com/coder/coder/codersdk"

cli/agent_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func TestWorkspaceAgent(t *testing.T) {
7272
require.NoError(t, err)
7373
defer dialer.Close()
7474
require.Eventually(t, func() bool {
75+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
76+
defer cancelFunc()
7577
_, err := dialer.Ping(ctx)
7678
return err == nil
7779
}, testutil.WaitMedium, testutil.IntervalFast)
@@ -133,6 +135,8 @@ func TestWorkspaceAgent(t *testing.T) {
133135
require.NoError(t, err)
134136
defer dialer.Close()
135137
require.Eventually(t, func() bool {
138+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
139+
defer cancelFunc()
136140
_, err := dialer.Ping(ctx)
137141
return err == nil
138142
}, testutil.WaitMedium, testutil.IntervalFast)
@@ -194,6 +198,8 @@ func TestWorkspaceAgent(t *testing.T) {
194198
require.NoError(t, err)
195199
defer dialer.Close()
196200
require.Eventually(t, func() bool {
201+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
202+
defer cancelFunc()
197203
_, err := dialer.Ping(ctx)
198204
return err == nil
199205
}, testutil.WaitMedium, testutil.IntervalFast)

coderd/workspaceagents_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ func TestWorkspaceAgentListen(t *testing.T) {
179179
_ = conn.Close()
180180
}()
181181
require.Eventually(t, func() bool {
182+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
183+
defer cancelFunc()
182184
_, err := conn.Ping(ctx)
183185
return err == nil
184186
}, testutil.WaitLong, testutil.IntervalFast)

0 commit comments

Comments
 (0)