(t *testing.T)
| 557 | } |
| 558 | |
| 559 | func TestConfigMaps_updatePeers_lost(t *testing.T) { |
| 560 | t.Parallel() |
| 561 | ctx := testutil.Context(t, testutil.WaitShort) |
| 562 | logger := testutil.Logger(t) |
| 563 | fEng := newFakeEngineConfigurable() |
| 564 | nodePrivateKey := key.NewNode() |
| 565 | nodeID := tailcfg.NodeID(5) |
| 566 | discoKey := key.NewDisco() |
| 567 | uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), CoderDNSSuffixFQDN) |
| 568 | defer uut.close() |
| 569 | mClock := quartz.NewMock(t) |
| 570 | start := mClock.Now() |
| 571 | uut.clock = mClock |
| 572 | |
| 573 | p1ID := uuid.UUID{1} |
| 574 | p1Node := newTestNode(1) |
| 575 | p1n, err := NodeToProto(p1Node) |
| 576 | require.NoError(t, err) |
| 577 | |
| 578 | s1 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) |
| 579 | |
| 580 | updates := []*proto.CoordinateResponse_PeerUpdate{ |
| 581 | { |
| 582 | Id: p1ID[:], |
| 583 | Kind: proto.CoordinateResponse_PeerUpdate_NODE, |
| 584 | Node: p1n, |
| 585 | }, |
| 586 | } |
| 587 | uut.updatePeers(updates) |
| 588 | nm := testutil.TryReceive(ctx, t, fEng.setNetworkMap) |
| 589 | r := testutil.TryReceive(ctx, t, fEng.reconfig) |
| 590 | require.Len(t, nm.Peers, 1) |
| 591 | require.Len(t, r.wg.Peers, 1) |
| 592 | _ = testutil.TryReceive(ctx, t, s1) |
| 593 | |
| 594 | mClock.Advance(5 * time.Second).MustWait(ctx) |
| 595 | |
| 596 | s2 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) |
| 597 | |
| 598 | updates[0].Kind = proto.CoordinateResponse_PeerUpdate_LOST |
| 599 | updates[0].Node = nil |
| 600 | uut.updatePeers(updates) |
| 601 | _ = testutil.TryReceive(ctx, t, s2) |
| 602 | |
| 603 | // No reprogramming yet, since we keep the peer around. |
| 604 | select { |
| 605 | case <-fEng.setNetworkMap: |
| 606 | t.Fatal("should not reprogram") |
| 607 | default: |
| 608 | // OK! |
| 609 | } |
| 610 | |
| 611 | // When we advance the clock, the timeout triggers. However, the new |
| 612 | // latest handshake has advanced by a minute, so we don't remove the peer. |
| 613 | lh := start.Add(time.Minute) |
| 614 | s3 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, lh) |
| 615 | // 5 seconds have already elapsed from above |
| 616 | mClock.Advance(lostTimeout - 5*time.Second).MustWait(ctx) |
nothing calls this directly
no test coverage detected