| 1076 | } |
| 1077 | |
| 1078 | func TestController_RetriesWrappedDeadlineExceeded(t *testing.T) { |
| 1079 | t.Parallel() |
| 1080 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 1081 | ctx, cancel := context.WithCancel(testCtx) |
| 1082 | defer cancel() |
| 1083 | |
| 1084 | logger := testutil.Logger(t) |
| 1085 | dialer := &scriptedDialer{ |
| 1086 | attempts: make(chan int, 10), |
| 1087 | dialFn: func(ctx context.Context, attempt int) (tailnet.ControlProtocolClients, error) { |
| 1088 | if attempt == 1 { |
| 1089 | return tailnet.ControlProtocolClients{}, &net.OpError{ |
| 1090 | Op: "dial", |
| 1091 | Net: "tcp", |
| 1092 | Err: context.DeadlineExceeded, |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | <-ctx.Done() |
| 1097 | return tailnet.ControlProtocolClients{}, ctx.Err() |
| 1098 | }, |
| 1099 | } |
| 1100 | |
| 1101 | uut := tailnet.NewController(logger.Named("ctrl"), dialer) |
| 1102 | uut.Run(ctx) |
| 1103 | |
| 1104 | require.Equal(t, 1, testutil.TryReceive(testCtx, t, dialer.attempts)) |
| 1105 | require.Equal(t, 2, testutil.TryReceive(testCtx, t, dialer.attempts)) |
| 1106 | |
| 1107 | select { |
| 1108 | case <-uut.Closed(): |
| 1109 | t.Fatal("controller exited after wrapped deadline exceeded") |
| 1110 | default: |
| 1111 | } |
| 1112 | |
| 1113 | cancel() |
| 1114 | _ = testutil.TryReceive(testCtx, t, uut.Closed()) |
| 1115 | } |
| 1116 | |
| 1117 | func TestController_DoesNotRedialAfterCancel(t *testing.T) { |
| 1118 | t.Parallel() |