MCPcopy
hub / github.com/tailscale/tailscale / TestAddPingRequest

Function TestAddPingRequest

tstest/integration/integration_test.go:1018–1068  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1016}
1017
1018func TestAddPingRequest(t *testing.T) {
1019 tstest.Parallel(t)
1020 env := NewTestEnv(t)
1021 n1 := NewTestNode(t, env)
1022 n1.StartDaemon()
1023
1024 n1.AwaitListening()
1025 n1.MustUp()
1026 n1.AwaitRunning()
1027
1028 gotPing := make(chan bool, 1)
1029 waitPing := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1030 gotPing <- true
1031 }))
1032 defer waitPing.Close()
1033
1034 nodes := env.Control.AllNodes()
1035 if len(nodes) != 1 {
1036 t.Fatalf("expected 1 node, got %d nodes", len(nodes))
1037 }
1038
1039 nodeKey := nodes[0].Key
1040
1041 // Check that we get at least one ping reply after 10 tries.
1042 for try := 1; try <= 10; try++ {
1043 t.Logf("ping %v ...", try)
1044 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1045 if err := env.Control.AwaitNodeInMapRequest(ctx, nodeKey); err != nil {
1046 t.Fatal(err)
1047 }
1048 cancel()
1049
1050 pr := &tailcfg.PingRequest{URL: fmt.Sprintf("%s/ping-%d", waitPing.URL, try), Log: true}
1051 if !env.Control.AddPingRequest(nodeKey, pr) {
1052 t.Logf("failed to AddPingRequest")
1053 continue
1054 }
1055
1056 // Wait for PingRequest to come back
1057 pingTimeout := time.NewTimer(2 * time.Second)
1058 defer pingTimeout.Stop()
1059 select {
1060 case <-gotPing:
1061 t.Logf("got ping; success")
1062 return
1063 case <-pingTimeout.C:
1064 // Try again.
1065 }
1066 }
1067 t.Error("all ping attempts failed")
1068}
1069
1070func TestC2NPingRequest(t *testing.T) {
1071 tstest.Parallel(t)

Callers

nothing calls this directly

Calls 15

StartDaemonMethod · 0.95
AwaitListeningMethod · 0.95
MustUpMethod · 0.95
AwaitRunningMethod · 0.95
CloseMethod · 0.95
StopMethod · 0.95
ParallelFunction · 0.92
NewTestEnvFunction · 0.85
NewTestNodeFunction · 0.85
AllNodesMethod · 0.80
AwaitNodeInMapRequestMethod · 0.80
AddPingRequestMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…