Skip to content

Commit

Permalink
fix: Add timeouts to every tailnet ping (#4986)
Browse files Browse the repository at this point in the history
A ping isn't guaranteed to deliver, so these need to have a
tight timeout for tests to not flake.
  • Loading branch information
kylecarbs committed Nov 9, 2022
1 parent 45f81a7 commit 16e9b1e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ func TestAgent(t *testing.T) {

conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0)
require.Eventually(t, func() bool {
_, err := conn.Ping(context.Background())
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.IntervalFast)
defer cancelFunc()
_, err := conn.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())
Expand Down
2 changes: 1 addition & 1 deletion agent/apphealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"
"time"

"golang.org/x/xerrors"
"github.com/google/uuid"
"golang.org/x/xerrors"

"cdr.dev/slog"
"github.com/coder/coder/codersdk"
Expand Down
6 changes: 6 additions & 0 deletions cli/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
Expand Down Expand Up @@ -133,6 +135,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
Expand Down Expand Up @@ -194,6 +198,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
Expand Down
2 changes: 2 additions & 0 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func TestWorkspaceAgentListen(t *testing.T) {
_ = conn.Close()
}()
require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := conn.Ping(ctx)
return err == nil
}, testutil.WaitLong, testutil.IntervalFast)
Expand Down

0 comments on commit 16e9b1e

Please sign in to comment.