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.
This commit is contained in:
Kyle Carberry
2022-11-09 14:12:51 -06:00
committed by GitHub
parent 45f81a7cd5
commit 16e9b1eb1a
4 changed files with 12 additions and 2 deletions

View File

@ -499,7 +499,9 @@ func TestAgent(t *testing.T) {
conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0) conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0)
require.Eventually(t, func() bool { 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 return err == nil
}, testutil.WaitMedium, testutil.IntervalFast) }, testutil.WaitMedium, testutil.IntervalFast)
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String()) conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())

View File

@ -6,8 +6,8 @@ import (
"sync" "sync"
"time" "time"
"golang.org/x/xerrors"
"github.com/google/uuid" "github.com/google/uuid"
"golang.org/x/xerrors"
"cdr.dev/slog" "cdr.dev/slog"
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"

View File

@ -72,6 +72,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer dialer.Close() defer dialer.Close()
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx) _, err := dialer.Ping(ctx)
return err == nil return err == nil
}, testutil.WaitMedium, testutil.IntervalFast) }, testutil.WaitMedium, testutil.IntervalFast)
@ -133,6 +135,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer dialer.Close() defer dialer.Close()
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx) _, err := dialer.Ping(ctx)
return err == nil return err == nil
}, testutil.WaitMedium, testutil.IntervalFast) }, testutil.WaitMedium, testutil.IntervalFast)
@ -194,6 +198,8 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer dialer.Close() defer dialer.Close()
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := dialer.Ping(ctx) _, err := dialer.Ping(ctx)
return err == nil return err == nil
}, testutil.WaitMedium, testutil.IntervalFast) }, testutil.WaitMedium, testutil.IntervalFast)

View File

@ -179,6 +179,8 @@ func TestWorkspaceAgentListen(t *testing.T) {
_ = conn.Close() _ = conn.Close()
}() }()
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
defer cancelFunc()
_, err := conn.Ping(ctx) _, err := conn.Ping(ctx)
return err == nil return err == nil
}, testutil.WaitLong, testutil.IntervalFast) }, testutil.WaitLong, testutil.IntervalFast)