(t *testing.T)
| 1016 | } |
| 1017 | |
| 1018 | func 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 | |
| 1070 | func TestC2NPingRequest(t *testing.T) { |
| 1071 | tstest.Parallel(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…