MCPcopy
hub / github.com/tailscale/tailscale / TestNodeBackendReadiness

Function TestNodeBackendReadiness

ipn/ipnlocal/node_backend_test.go:18–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestNodeBackendReadiness(t *testing.T) {
19 nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
20
21 // The node backend is not ready until [nodeBackend.ready] is called,
22 // and [nodeBackend.Wait] should fail with [context.DeadlineExceeded].
23 ctx, cancelCtx := context.WithTimeout(context.Background(), 100*time.Millisecond)
24 defer cancelCtx()
25 if err := nb.Wait(ctx); err != ctx.Err() {
26 t.Fatalf("Wait: got %v; want %v", err, ctx.Err())
27 }
28
29 // Start a goroutine to wait for the node backend to become ready.
30 waitDone := make(chan struct{})
31 go func() {
32 if err := nb.Wait(context.Background()); err != nil {
33 t.Errorf("Wait: got %v; want nil", err)
34 }
35 close(waitDone)
36 }()
37
38 // Call [nodeBackend.ready] to indicate that the node backend is now ready.
39 go nb.ready()
40
41 // Once the backend is called, [nodeBackend.Wait] should return immediately without error.
42 if err := nb.Wait(context.Background()); err != nil {
43 t.Fatalf("Wait: got %v; want nil", err)
44 }
45 // And any pending waiters should also be unblocked.
46 <-waitDone
47}
48
49func TestNodeBackendShutdown(t *testing.T) {
50 nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())

Callers

nothing calls this directly

Calls 9

WhileTestRunningLoggerFunction · 0.92
NewFunction · 0.92
newNodeBackendFunction · 0.85
readyMethod · 0.80
ContextMethod · 0.65
WaitMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…