MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestUpdateDiscoForNodeCallback

Function TestUpdateDiscoForNodeCallback

control/controlclient/map_test.go:792–915  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

790}
791
792func TestUpdateDiscoForNodeCallback(t *testing.T) {
793 t.Run("key_wired_through_to_updater", func(t *testing.T) {
794 nu := &rememberLastNetmapUpdater{
795 done: make(chan any, 1),
796 }
797 ms := newTestMapSession(t, nu)
798
799 oldKey := key.NewDisco()
800
801 // Insert existing node
802 node := tailcfg.Node{
803 ID: 1,
804 Key: key.NewNode().Public(),
805 DiscoKey: oldKey.Public(),
806 Online: new(false),
807 LastSeen: new(time.Unix(1, 0)),
808 }
809
810 if nm := ms.netmapForResponse(&tailcfg.MapResponse{
811 Peers: []*tailcfg.Node{&node},
812 }); len(nm.Peers) != 1 {
813 t.Fatalf("node not inserted")
814 }
815
816 newKey := key.NewDisco()
817 ms.updateDiscoForNode(node.ID, node.Key, newKey.Public(), time.Now(), false)
818 <-nu.done
819
820 if nu.lastTSMPKey != node.Key || nu.lastTSMPDisco != newKey.Public() {
821 t.Fatalf("expected [%s]=%s, got [%s]=%s", node.Key, newKey.Public(),
822 nu.lastTSMPKey, nu.lastTSMPDisco)
823 }
824 })
825 // Even though key stays in list of update, the updater only triggers on TSMP.
826 t.Run("key_not_wired_through_to_updater", func(t *testing.T) {
827 nu := &rememberLastNetmapUpdater{
828 done: make(chan any, 1),
829 }
830 ms := newTestMapSession(t, nu)
831
832 oldKey := key.NewDisco()
833
834 // Insert existing node
835 node := tailcfg.Node{
836 ID: 1,
837 Key: key.NewNode().Public(),
838 DiscoKey: oldKey.Public(),
839 Online: new(false),
840 LastSeen: new(time.Unix(1, 0)),
841 }
842
843 if nm := ms.netmapForResponse(&tailcfg.MapResponse{
844 Peers: []*tailcfg.Node{&node},
845 }); len(nm.Peers) != 1 {
846 t.Fatalf("node not inserted")
847 }
848
849 newKey := key.NewDisco().Public()

Callers

nothing calls this directly

Calls 13

NewDiscoFunction · 0.92
NewNodeFunction · 0.92
newTestMapSessionFunction · 0.85
netmapForResponseMethod · 0.80
updateDiscoForNodeMethod · 0.80
RunMethod · 0.65
FatalfMethod · 0.65
NowMethod · 0.65
ContextMethod · 0.65
IsZeroMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…