Skip to content

Commit 0de5a45

Browse files
committed
chore(enterprise/coderd/coderdenttest): ensure WorkspaceProxy is connected before returning
1 parent 38755e2 commit 0de5a45

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

enterprise/coderd/coderdenttest/proxytest.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func NewWorkspaceProxyReplica(t *testing.T, coderdAPI *coderd.API, owner *coders
6868
t.Helper()
6969

7070
ctx, cancelFunc := context.WithCancel(context.Background())
71-
t.Cleanup(cancelFunc)
7271

7372
if options == nil {
7473
options = &ProxyOptions{}
@@ -179,6 +178,23 @@ func NewWorkspaceProxyReplica(t *testing.T, coderdAPI *coderd.API, owner *coders
179178
handler = wssrv.Handler
180179
mutex.Unlock()
181180

181+
// Wait for the tailnet connection to be established before returning.
182+
// Returning the proxy before it's connected may lead to test ending
183+
// before the proxy is fully connected, which will result in an error log
184+
// that may fail the test.
185+
waitCtx, waitCancel := context.WithTimeout(ctx, testutil.WaitShort)
186+
defer waitCancel()
187+
dialer, err := wssrv.SDKClient.TailnetDialer()
188+
require.NoError(t, err, "create test tailnet dialer")
189+
190+
select {
191+
case <-dialer.Connected():
192+
t.Logf("Test dialer connected")
193+
case <-waitCtx.Done():
194+
t.Logf("Waiting for tailnet connection timed out or was canceled: %v", waitCtx.Err())
195+
}
196+
t.Cleanup(cancelFunc)
197+
182198
return WorkspaceProxy{
183199
Server: wssrv,
184200
ServerURL: serverURL,

0 commit comments

Comments
 (0)