MCPcopy Create free account
hub / github.com/coder/coder / TestTunnelSrcCoordController_Sync

Function TestTunnelSrcCoordController_Sync

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

Source from the content-addressed store, hash-verified

310}
311
312func TestTunnelSrcCoordController_Sync(t *testing.T) {
313 t.Parallel()
314 ctx := testutil.Context(t, testutil.WaitShort)
315 logger := testutil.Logger(t)
316
317 fConn := &fakeCoordinatee{}
318 uut := tailnet.NewTunnelSrcCoordController(logger, fConn)
319 dest1 := uuid.UUID{1}
320 dest2 := uuid.UUID{2}
321 dest3 := uuid.UUID{3}
322
323 // GIVEN: dest1 & dest2 already added
324 uut.AddDestination(dest1)
325 uut.AddDestination(dest2)
326
327 // GIVEN: client already connected
328 client1 := newFakeCoordinatorClient(ctx, t)
329 cws := make(chan tailnet.CloserWaiter)
330 go func() {
331 cws <- uut.New(client1)
332 }()
333 for range 2 {
334 call := testutil.TryReceive(ctx, t, client1.reqs)
335 testutil.RequireSend(ctx, t, call.err, nil)
336 }
337 cw1 := testutil.TryReceive(ctx, t, cws)
338
339 // WHEN: we sync dest2 & dest3
340 syncDone := make(chan struct{})
341 go func() {
342 defer close(syncDone)
343 uut.SyncDestinations([]uuid.UUID{dest2, dest3})
344 }()
345
346 // THEN: we get an add for dest3 and remove for dest1
347 call := testutil.TryReceive(ctx, t, client1.reqs)
348 require.Equal(t, dest3[:], call.req.GetAddTunnel().GetId())
349 testutil.RequireSend(ctx, t, call.err, nil)
350 call = testutil.TryReceive(ctx, t, client1.reqs)
351 require.Equal(t, dest1[:], call.req.GetRemoveTunnel().GetId())
352 testutil.RequireSend(ctx, t, call.err, nil)
353
354 testutil.TryReceive(ctx, t, syncDone)
355 // dest3 should be added to coordinatee
356 require.Contains(t, fConn.tunnelDestinations, dest3)
357
358 // shut down
359 respCall := testutil.TryReceive(ctx, t, client1.resps)
360 testutil.RequireSend(ctx, t, respCall.err, io.EOF)
361 closeCall := testutil.TryReceive(ctx, t, client1.close)
362 testutil.RequireSend(ctx, t, closeCall, nil)
363 err := testutil.TryReceive(ctx, t, cw1.Wait())
364 require.ErrorIs(t, err, io.EOF)
365}
366
367func TestTunnelSrcCoordController_AddDestination_Error(t *testing.T) {
368 t.Parallel()

Callers

nothing calls this directly

Calls 15

AddDestinationMethod · 0.95
NewMethod · 0.95
SyncDestinationsMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeCoordinatorClientFunction · 0.85
GetAddTunnelMethod · 0.80
GetRemoveTunnelMethod · 0.80
WaitMethod · 0.65

Tested by

no test coverage detected