MCPcopy Index your code
hub / github.com/coder/coder / TestNodeUpdater_setNetInfo_different

Function TestNodeUpdater_setNetInfo_different

tailnet/node_internal_test.go:20–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestNodeUpdater_setNetInfo_different(t *testing.T) {
21 t.Parallel()
22 ctx := testutil.Context(t, testutil.WaitShort)
23 logger := testutil.Logger(t)
24 id := tailcfg.NodeID(1)
25 nodeKey := key.NewNode().Public()
26 discoKey := key.NewDisco().Public()
27 nodeCh := make(chan *Node)
28 goCh := make(chan struct{})
29 uut := newNodeUpdater(
30 logger,
31 func(n *Node) {
32 nodeCh <- n
33 <-goCh
34 },
35 id, nodeKey, discoKey,
36 )
37 defer uut.close()
38
39 dl := map[string]float64{"1": 0.025}
40 uut.setNetInfo(&tailcfg.NetInfo{
41 PreferredDERP: 1,
42 DERPLatency: dl,
43 })
44
45 node := testutil.TryReceive(ctx, t, nodeCh)
46 require.Equal(t, nodeKey, node.Key)
47 require.Equal(t, discoKey, node.DiscoKey)
48 require.Equal(t, 1, node.PreferredDERP)
49 require.True(t, maps.Equal(dl, node.DERPLatency))
50
51 // Send in second update to test getting updates in the middle of the
52 // callback
53 uut.setNetInfo(&tailcfg.NetInfo{
54 PreferredDERP: 2,
55 DERPLatency: dl,
56 })
57 close(goCh) // allows callback to complete
58
59 node = testutil.TryReceive(ctx, t, nodeCh)
60 require.Equal(t, nodeKey, node.Key)
61 require.Equal(t, discoKey, node.DiscoKey)
62 require.Equal(t, 2, node.PreferredDERP)
63 require.True(t, maps.Equal(dl, node.DERPLatency))
64
65 done := make(chan struct{})
66 go func() {
67 defer close(done)
68 uut.close()
69 }()
70 _ = testutil.TryReceive(ctx, t, done)
71}
72
73func TestNodeUpdater_setNetInfo_same(t *testing.T) {
74 t.Parallel()

Callers

nothing calls this directly

Calls 7

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newNodeUpdaterFunction · 0.85
closeMethod · 0.65
setNetInfoMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected