(t *testing.T)
| 489 | } |
| 490 | |
| 491 | func TestConfigMaps_updatePeers_disconnect(t *testing.T) { |
| 492 | t.Parallel() |
| 493 | ctx := testutil.Context(t, testutil.WaitShort) |
| 494 | logger := testutil.Logger(t) |
| 495 | fEng := newFakeEngineConfigurable() |
| 496 | nodePrivateKey := key.NewNode() |
| 497 | nodeID := tailcfg.NodeID(5) |
| 498 | discoKey := key.NewDisco() |
| 499 | uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), CoderDNSSuffixFQDN) |
| 500 | defer uut.close() |
| 501 | |
| 502 | p1ID := uuid.UUID{1} |
| 503 | p1Node := newTestNode(1) |
| 504 | p1n, err := NodeToProto(p1Node) |
| 505 | require.NoError(t, err) |
| 506 | p1tcn, err := uut.protoNodeToTailcfg(p1n) |
| 507 | p1tcn.KeepAlive = true |
| 508 | require.NoError(t, err) |
| 509 | |
| 510 | // set a timer, which should get canceled by the disconnect. |
| 511 | timer := uut.clock.AfterFunc(testutil.WaitMedium, func() { |
| 512 | t.Error("this should not be called!") |
| 513 | }) |
| 514 | |
| 515 | // Given: peer already exists |
| 516 | uut.L.Lock() |
| 517 | uut.peers[p1ID] = &peerLifecycle{ |
| 518 | peerID: p1ID, |
| 519 | node: p1tcn, |
| 520 | lastHandshake: time.Date(2024, 1, 7, 12, 0, 10, 0, time.UTC), |
| 521 | lostTimer: timer, |
| 522 | } |
| 523 | uut.L.Unlock() |
| 524 | |
| 525 | go func() { |
| 526 | b := <-fEng.status |
| 527 | b.AddPeer(p1Node.Key, &ipnstate.PeerStatus{ |
| 528 | PublicKey: p1Node.Key, |
| 529 | LastHandshake: time.Date(2024, 1, 7, 12, 13, 10, 0, time.UTC), |
| 530 | Active: true, |
| 531 | }) |
| 532 | fEng.statusDone <- struct{}{} |
| 533 | }() |
| 534 | |
| 535 | // When: update DISCONNECTED |
| 536 | updates := []*proto.CoordinateResponse_PeerUpdate{ |
| 537 | { |
| 538 | Id: p1ID[:], |
| 539 | Kind: proto.CoordinateResponse_PeerUpdate_DISCONNECTED, |
| 540 | }, |
| 541 | } |
| 542 | uut.updatePeers(updates) |
| 543 | assert.False(t, timer.Stop(), "timer was not stopped") |
| 544 | |
| 545 | // Then, configure engine without the peer. |
| 546 | nm := testutil.TryReceive(ctx, t, fEng.setNetworkMap) |
| 547 | r := testutil.TryReceive(ctx, t, fEng.reconfig) |
| 548 | require.Len(t, nm.Peers, 0) |
nothing calls this directly
no test coverage detected