(t *testing.T)
| 995 | } |
| 996 | |
| 997 | func TestController_Disconnects(t *testing.T) { |
| 998 | t.Parallel() |
| 999 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 1000 | ctx, cancel := context.WithCancel(testCtx) |
| 1001 | logger := slogtest.Make(t, &slogtest.Options{ |
| 1002 | IgnoredErrorIs: append(slogtest.DefaultIgnoredErrorIs, |
| 1003 | io.EOF, // we get EOF when we simulate a DERPMap error |
| 1004 | yamux.ErrSessionShutdown, // coordination can throw these when DERP error tears down session |
| 1005 | ), |
| 1006 | }).Leveled(slog.LevelDebug) |
| 1007 | agentID := uuid.UUID{0x55} |
| 1008 | clientID := uuid.UUID{0x66} |
| 1009 | fCoord := tailnettest.NewFakeCoordinator() |
| 1010 | var coord tailnet.Coordinator = fCoord |
| 1011 | coordPtr := atomic.Pointer[tailnet.Coordinator]{} |
| 1012 | coordPtr.Store(&coord) |
| 1013 | derpMapCh := make(chan *tailcfg.DERPMap) |
| 1014 | defer close(derpMapCh) |
| 1015 | svc, err := tailnet.NewClientService(tailnet.ClientServiceOptions{ |
| 1016 | Logger: logger.Named("svc"), |
| 1017 | CoordPtr: &coordPtr, |
| 1018 | DERPMapUpdateFrequency: time.Millisecond, |
| 1019 | DERPMapFn: func() *tailcfg.DERPMap { return <-derpMapCh }, |
| 1020 | NetworkTelemetryHandler: func([]*proto.TelemetryEvent) {}, |
| 1021 | ResumeTokenProvider: tailnet.NewInsecureTestResumeTokenProvider(), |
| 1022 | }) |
| 1023 | require.NoError(t, err) |
| 1024 | |
| 1025 | dialer := &pipeDialer{ |
| 1026 | ctx: testCtx, |
| 1027 | logger: logger, |
| 1028 | t: t, |
| 1029 | svc: svc, |
| 1030 | streamID: tailnet.StreamID{ |
| 1031 | Name: "client", |
| 1032 | ID: clientID, |
| 1033 | Auth: tailnet.ClientCoordinateeAuth{AgentID: agentID}, |
| 1034 | }, |
| 1035 | } |
| 1036 | |
| 1037 | peersLost := make(chan struct{}) |
| 1038 | fConn := &fakeTailnetConn{peersLostCh: peersLost} |
| 1039 | |
| 1040 | uut := tailnet.NewController(logger.Named("ctrl"), dialer, |
| 1041 | // darwin can be slow sometimes. |
| 1042 | tailnet.WithGracefulTimeout(5*time.Second)) |
| 1043 | uut.CoordCtrl = tailnet.NewAgentCoordinationController(logger.Named("coord_ctrl"), fConn) |
| 1044 | uut.DERPCtrl = tailnet.NewBasicDERPController(logger.Named("derp_ctrl"), nil, fConn) |
| 1045 | uut.Run(ctx) |
| 1046 | |
| 1047 | call := testutil.TryReceive(testCtx, t, fCoord.CoordinateCalls) |
| 1048 | |
| 1049 | // simulate a problem with DERPMaps by sending nil |
| 1050 | testutil.RequireSend(testCtx, t, derpMapCh, nil) |
| 1051 | |
| 1052 | // this should cause the coordinate call to hang up WITHOUT disconnecting |
| 1053 | reqNil := testutil.TryReceive(testCtx, t, call.Reqs) |
| 1054 | require.Nil(t, reqNil) |
nothing calls this directly
no test coverage detected