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

Function TestConfigMaps_setAddresses_different

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

Source from the content-addressed store, hash-verified

27)
28
29func TestConfigMaps_setAddresses_different(t *testing.T) {
30 t.Parallel()
31 ctx := testutil.Context(t, testutil.WaitShort)
32 logger := testutil.Logger(t)
33 fEng := newFakeEngineConfigurable()
34 nodePrivateKey := key.NewNode()
35 nodeID := tailcfg.NodeID(5)
36 discoKey := key.NewDisco()
37 uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), CoderDNSSuffixFQDN)
38 defer uut.close()
39
40 addrs := []netip.Prefix{netip.MustParsePrefix("192.168.0.200/32")}
41 uut.setAddresses(addrs)
42
43 nm := testutil.TryReceive(ctx, t, fEng.setNetworkMap)
44 require.Equal(t, addrs, nm.Addresses)
45
46 // here were in the middle of a reconfig, blocked on a channel write to fEng.reconfig
47 locked := uut.L.(*sync.Mutex).TryLock()
48 require.True(t, locked)
49 require.Equal(t, configuring, uut.phase)
50 uut.L.Unlock()
51 // send in another update while blocked
52 addrs2 := []netip.Prefix{
53 netip.MustParsePrefix("192.168.0.200/32"),
54 netip.MustParsePrefix("10.20.30.40/32"),
55 }
56 uut.setAddresses(addrs2)
57
58 r := testutil.TryReceive(ctx, t, fEng.reconfig)
59 require.Equal(t, addrs, r.wg.Addresses)
60 require.Equal(t, addrs, r.router.LocalAddrs)
61 f := testutil.TryReceive(ctx, t, fEng.filter)
62 fr := f.CheckTCP(netip.MustParseAddr("33.44.55.66"), netip.MustParseAddr("192.168.0.200"), 5555)
63 require.Equal(t, filter.Accept, fr)
64 fr = f.CheckTCP(netip.MustParseAddr("33.44.55.66"), netip.MustParseAddr("10.20.30.40"), 5555)
65 require.Equal(t, filter.Drop, fr, "first addr config should not include 10.20.30.40")
66
67 // we should get another round of configurations from the second set of addrs
68 nm = testutil.TryReceive(ctx, t, fEng.setNetworkMap)
69 require.Equal(t, addrs2, nm.Addresses)
70 r = testutil.TryReceive(ctx, t, fEng.reconfig)
71 require.Equal(t, addrs2, r.wg.Addresses)
72 require.Equal(t, addrs2, r.router.LocalAddrs)
73 f = testutil.TryReceive(ctx, t, fEng.filter)
74 fr = f.CheckTCP(netip.MustParseAddr("33.44.55.66"), netip.MustParseAddr("192.168.0.200"), 5555)
75 require.Equal(t, filter.Accept, fr)
76 fr = f.CheckTCP(netip.MustParseAddr("33.44.55.66"), netip.MustParseAddr("10.20.30.40"), 5555)
77 require.Equal(t, filter.Accept, fr)
78
79 done := make(chan struct{})
80 go func() {
81 defer close(done)
82 uut.close()
83 }()
84 _ = testutil.TryReceive(ctx, t, done)
85}
86

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newConfigMapsFunction · 0.85
closeMethod · 0.65
setAddressesMethod · 0.45
EqualMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected