(t *testing.T)
| 192 | } |
| 193 | |
| 194 | func 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) |
nothing calls this directly
no test coverage detected