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

Function TestTunnelSrcCoordController_RemoveDestination

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

Source from the content-addressed store, hash-verified

192}
193
194func TestTunnelSrcCoordController_RemoveDestination(t *testing.T) {
195 t.Parallel()
196 ctx := testutil.Context(t, testutil.WaitShort)
197 logger := testutil.Logger(t)
198
199 fConn := &fakeCoordinatee{}
200 uut := tailnet.NewTunnelSrcCoordController(logger, fConn)
201
202 // GIVEN: 1 destination
203 dest1 := uuid.UUID{1}
204 uut.AddDestination(dest1)
205
206 // GIVEN: client already connected
207 client1 := newFakeCoordinatorClient(ctx, t)
208 cws := make(chan tailnet.CloserWaiter)
209 go func() {
210 cws <- uut.New(client1)
211 }()
212 call := testutil.TryReceive(ctx, t, client1.reqs)
213 testutil.RequireSend(ctx, t, call.err, nil)
214 cw1 := testutil.TryReceive(ctx, t, cws)
215
216 // WHEN: we remove one destination
217 removeDone := make(chan struct{})
218 go func() {
219 defer close(removeDone)
220 uut.RemoveDestination(dest1)
221 }()
222
223 // THEN: Controller sends RemoveTunnel for the destination
224 call = testutil.TryReceive(ctx, t, client1.reqs)
225 require.Equal(t, dest1[:], call.req.GetRemoveTunnel().GetId())
226 testutil.RequireSend(ctx, t, call.err, nil)
227 _ = testutil.TryReceive(ctx, t, removeDone)
228
229 // WHEN: Closed from server side and reconnect
230 respCall := testutil.TryReceive(ctx, t, client1.resps)
231 testutil.RequireSend(ctx, t, respCall.err, io.EOF)
232 closeCall := testutil.TryReceive(ctx, t, client1.close)
233 testutil.RequireSend(ctx, t, closeCall, nil)
234 err := testutil.TryReceive(ctx, t, cw1.Wait())
235 require.ErrorIs(t, err, io.EOF)
236
237 client2 := newFakeCoordinatorClient(ctx, t)
238 go func() {
239 cws <- uut.New(client2)
240 }()
241
242 // THEN: should immediately resolve without sending anything
243 cw2 := testutil.TryReceive(ctx, t, cws)
244
245 // close client2
246 respCall = testutil.TryReceive(ctx, t, client2.resps)
247 testutil.RequireSend(ctx, t, respCall.err, io.EOF)
248 closeCall = testutil.TryReceive(ctx, t, client2.close)
249 testutil.RequireSend(ctx, t, closeCall, nil)
250 err = testutil.TryReceive(ctx, t, cw2.Wait())
251 require.ErrorIs(t, err, io.EOF)

Callers

nothing calls this directly

Calls 13

AddDestinationMethod · 0.95
NewMethod · 0.95
RemoveDestinationMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeCoordinatorClientFunction · 0.85
GetRemoveTunnelMethod · 0.80
WaitMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected