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

Function TestNodeUpdater_setStatus_different

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

Source from the content-addressed store, hash-verified

189}
190
191func TestNodeUpdater_setStatus_different(t *testing.T) {
192 t.Parallel()
193 ctx := testutil.Context(t, testutil.WaitShort)
194 logger := testutil.Logger(t)
195 id := tailcfg.NodeID(1)
196 nodeKey := key.NewNode().Public()
197 discoKey := key.NewDisco().Public()
198 nodeCh := make(chan *Node)
199 uut := newNodeUpdater(
200 logger,
201 func(n *Node) {
202 nodeCh <- n
203 },
204 id, nodeKey, discoKey,
205 )
206 defer uut.close()
207
208 // Given: preferred DERP is 1, so we'll send an update
209 uut.L.Lock()
210 uut.preferredDERP = 1
211 uut.L.Unlock()
212
213 // When: we set a new status
214 asof := time.Date(2024, 1, 10, 8, 0o0, 1, 1, time.UTC)
215 uut.setStatus(&wgengine.Status{
216 LocalAddrs: []tailcfg.Endpoint{
217 {Addr: netip.MustParseAddrPort("[fe80::1]:5678")},
218 },
219 AsOf: asof,
220 }, nil)
221
222 // Then: we receive an update with the endpoint
223 node := testutil.TryReceive(ctx, t, nodeCh)
224 require.Equal(t, nodeKey, node.Key)
225 require.Equal(t, discoKey, node.DiscoKey)
226 require.Equal(t, []string{"[fe80::1]:5678"}, node.Endpoints)
227
228 // Then: we store the AsOf time as lastStatus
229 uut.L.Lock()
230 require.Equal(t, uut.lastStatus, asof)
231 uut.L.Unlock()
232
233 done := make(chan struct{})
234 go func() {
235 defer close(done)
236 uut.close()
237 }()
238 _ = testutil.TryReceive(ctx, t, done)
239}
240
241func TestNodeUpdater_setStatus_same(t *testing.T) {
242 t.Parallel()

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newNodeUpdaterFunction · 0.85
setStatusMethod · 0.80
closeMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected