MCPcopy Create free account
hub / github.com/coder/coder / TestConfigMaps_updatePeers_disconnect

Function TestConfigMaps_updatePeers_disconnect

tailnet/configmaps_internal_test.go:491–557  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

489}
490
491func 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)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newConfigMapsFunction · 0.85
newTestNodeFunction · 0.85
NodeToProtoFunction · 0.85
protoNodeToTailcfgMethod · 0.80
updatePeersMethod · 0.80
closeMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected