MCPcopy
hub / github.com/tailscale/tailscale / setupTwoClientTest

Function setupTwoClientTest

tsnet/tsnet_test.go:2321–2378  ·  view source on GitHub ↗

setupTwoClientTest creates two tsnet servers for testing. If useTUN is true, s2 uses a chanTUN; otherwise it uses netstack only.

(t *testing.T, useTUN bool)

Source from the content-addressed store, hash-verified

2319// setupTwoClientTest creates two tsnet servers for testing.
2320// If useTUN is true, s2 uses a chanTUN; otherwise it uses netstack only.
2321func setupTwoClientTest(t *testing.T, useTUN bool) *listenTest {
2322 t.Helper()
2323 tstest.ResourceCheck(t)
2324 ctx := t.Context()
2325 controlURL, control := startControl(t)
2326 s1, _, _ := startServer(t, ctx, controlURL, "s1")
2327
2328 tmp := filepath.Join(t.TempDir(), "s2")
2329 must.Do(os.MkdirAll(tmp, 0755))
2330 s2 := &Server{
2331 Dir: tmp,
2332 ControlURL: controlURL,
2333 Hostname: "s2",
2334 Store: new(mem.Store),
2335 Ephemeral: true,
2336 }
2337
2338 var tun *chanTUN
2339 if useTUN {
2340 tun = newChanTUN()
2341 s2.Tun = tun
2342 }
2343
2344 if *verboseNodes {
2345 s2.Logf = t.Logf
2346 }
2347 t.Cleanup(func() { s2.Close() })
2348
2349 s2status, err := s2.Up(ctx)
2350 if err != nil {
2351 t.Fatal(err)
2352 }
2353 s2.lb.ConfigureCertsForTest(testCertRoot.getCert)
2354
2355 s1ip4, s1ip6 := s1.TailscaleIPs()
2356 s2ip4 := s2status.TailscaleIPs[0]
2357 var s2ip6 netip.Addr
2358 if len(s2status.TailscaleIPs) > 1 {
2359 s2ip6 = s2status.TailscaleIPs[1]
2360 }
2361
2362 waitForPeerReachable(t, s1, s2.lb.NodeKey())
2363 waitForPeerReachable(t, s2, s1.lb.NodeKey())
2364
2365 lc1 := must.Get(s1.LocalClient())
2366 must.Get(lc1.Ping(ctx, s2ip4, tailcfg.PingTSMP))
2367
2368 return &listenTest{
2369 control: control,
2370 s1: s1,
2371 s2: s2,
2372 s1ip4: s1ip4,
2373 s1ip6: s1ip6,
2374 s2ip4: s2ip4,
2375 s2ip6: s2ip6,
2376 tun: tun,
2377 }
2378}

Callers 10

TestListenServiceFunction · 0.85
TestTUNFunction · 0.85
TestTUNDNSFunction · 0.85
TestListenPacketFunction · 0.85
TestListenTCPFunction · 0.85
TestListenTCPDualStackFunction · 0.85
TestDialTCPFunction · 0.85
TestDialUDPFunction · 0.85

Calls 15

CloseMethod · 0.95
UpMethod · 0.95
ResourceCheckFunction · 0.92
DoFunction · 0.92
GetFunction · 0.92
startServerFunction · 0.85
newChanTUNFunction · 0.85
waitForPeerReachableFunction · 0.85
ConfigureCertsForTestMethod · 0.80
TailscaleIPsMethod · 0.80
startControlFunction · 0.70
HelperMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…