| 332 | } |
| 333 | |
| 334 | func waitForServerAvailable(t *testing.T, serverURL *url.URL) { |
| 335 | const delay = 100 * time.Millisecond |
| 336 | const reqTimeout = 2 * time.Second |
| 337 | const timeout = 30 * time.Second |
| 338 | client := http.Client{ |
| 339 | Timeout: reqTimeout, |
| 340 | } |
| 341 | |
| 342 | u, err := url.Parse(serverURL.String() + "/derp/latency-check") |
| 343 | require.NoError(t, err) |
| 344 | for start := time.Now(); time.Since(start) < timeout; time.Sleep(delay) { |
| 345 | //nolint:noctx |
| 346 | resp, err := client.Get(u.String()) |
| 347 | if err != nil { |
| 348 | t.Logf("waiting for server to be available: %v", err) |
| 349 | continue |
| 350 | } |
| 351 | _ = resp.Body.Close() |
| 352 | if resp.StatusCode != http.StatusOK { |
| 353 | t.Logf("waiting for server to be available: got status %d", resp.StatusCode) |
| 354 | continue |
| 355 | } |
| 356 | return |
| 357 | } |
| 358 | |
| 359 | t.Fatalf("server did not become available after %v", timeout) |
| 360 | } |
| 361 | |
| 362 | func startServerSubprocess(t *testing.T, topologyName string, networking integration.TestNetworking) func() error { |
| 363 | _, closeFn := startSubprocess(t, "server", networking.Server.Process.NetNS, []string{ |