MCPcopy Index your code
hub / github.com/coder/coder / TestController_DoesNotRedialAfterCancel

Function TestController_DoesNotRedialAfterCancel

tailnet/controllers_test.go:1117–1154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1115}
1116
1117func TestController_DoesNotRedialAfterCancel(t *testing.T) {
1118 t.Parallel()
1119 testCtx := testutil.Context(t, testutil.WaitShort)
1120 ctx, cancel := context.WithCancel(testCtx)
1121 logger := testutil.Logger(t)
1122
1123 fClient := newFakeWorkspaceUpdateClient(testCtx, t)
1124 dialer := &scriptedDialer{
1125 attempts: make(chan int, 10),
1126 dialFn: func(_ context.Context, _ int) (tailnet.ControlProtocolClients, error) {
1127 return tailnet.ControlProtocolClients{
1128 WorkspaceUpdates: fClient,
1129 Closer: fakeCloser{},
1130 }, nil
1131 },
1132 }
1133 fCtrl := newFakeUpdatesController(testCtx, t)
1134
1135 uut := tailnet.NewController(logger.Named("ctrl"), dialer)
1136 uut.WorkspaceUpdatesCtrl = fCtrl
1137 uut.Run(ctx)
1138
1139 require.Equal(t, 1, testutil.TryReceive(testCtx, t, dialer.attempts))
1140 call := testutil.TryReceive(testCtx, t, fCtrl.calls)
1141 require.Equal(t, fClient, call.client)
1142 testutil.RequireSend[tailnet.CloserWaiter](testCtx, t, call.resp, newFakeCloserWaiter())
1143
1144 cancel()
1145 closeCall := testutil.TryReceive(testCtx, t, fClient.close)
1146 testutil.RequireSend(testCtx, t, closeCall, nil)
1147 _ = testutil.TryReceive(testCtx, t, uut.Closed())
1148
1149 select {
1150 case attempt := <-dialer.attempts:
1151 t.Fatalf("unexpected redial attempt after cancel: %d", attempt)
1152 default:
1153 }
1154}
1155
1156func TestController_TelemetrySuccess(t *testing.T) {
1157 t.Parallel()

Callers

nothing calls this directly

Calls 13

RunMethod · 0.95
ClosedMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NewControllerFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeUpdatesControllerFunction · 0.85
newFakeCloserWaiterFunction · 0.85
NamedMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected