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 20:12:51 +00:00
committed by GitHub
parent 45f81a7cd5
commit 16e9b1eb1a
4 changed files with 12 additions and 2 deletions
+3 -1
View File
@@ -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())
+1 -1
View File
@@ -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"
+6
View File
@@ -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)
@@ -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)
@@ -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)
+2
View File
@@ -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)