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

Function TestConn_PreferredDERP

tailnet/conn_test.go:251–278  ·  view source on GitHub ↗

TestConn_PreferredDERP tests that we only trigger the NodeCallback when we have a preferred DERP server.

(t *testing.T)

Source from the content-addressed store, hash-verified

249
250// TestConn_PreferredDERP tests that we only trigger the NodeCallback when we have a preferred DERP server.
251func TestConn_PreferredDERP(t *testing.T) {
252 t.Parallel()
253 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
254 defer cancel()
255 logger := testutil.Logger(t)
256 derpMap, _ := tailnettest.RunDERPAndSTUN(t)
257 conn, err := tailnet.NewConn(&tailnet.Options{
258 Addresses: []netip.Prefix{tailnet.TailscaleServicePrefix.RandomPrefix()},
259 Logger: logger.Named("w1"),
260 DERPMap: derpMap,
261 })
262 require.NoError(t, err)
263 defer func() {
264 err := conn.Close()
265 require.NoError(t, err)
266 }()
267 // buffer channel so callback doesn't block
268 nodes := make(chan *tailnet.Node, 50)
269 conn.SetNodeCallback(func(node *tailnet.Node) {
270 nodes <- node
271 })
272 select {
273 case node := <-nodes:
274 require.Equal(t, 1, node.PreferredDERP)
275 case <-ctx.Done():
276 t.Fatal("timed out waiting for node")
277 }
278}
279
280// TestConn_UpdateDERP tests that when update the DERP map we pick a new
281// preferred DERP server and new connections can be made from clients.

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
SetNodeCallbackMethod · 0.95
LoggerFunction · 0.92
RunDERPAndSTUNFunction · 0.92
NewConnFunction · 0.92
RandomPrefixMethod · 0.80
NamedMethod · 0.80
FatalMethod · 0.80
EqualMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected