MCPcopy Index your code
hub / github.com/coder/agentapi / waitForServer

Function waitForServer

e2e/echo_test.go:444–466  ·  view source on GitHub ↗

waitForServer waits for a server to be ready

(ctx context.Context, t testing.TB, url string, timeout time.Duration)

Source from the content-addressed store, hash-verified

442
443// waitForServer waits for a server to be ready
444func waitForServer(ctx context.Context, t testing.TB, url string, timeout time.Duration) error {
445 t.Helper()
446 client := &http.Client{Timeout: time.Second}
447 healthCtx, cancel := context.WithTimeout(ctx, timeout)
448 defer cancel()
449
450 ticker := time.NewTicker(100 * time.Millisecond)
451 defer ticker.Stop()
452
453 for {
454 select {
455 case <-healthCtx.Done():
456 require.Failf(t, "failed to start server", "server at %s not ready within timeout: %w", url, healthCtx.Err())
457 case <-ticker.C:
458 resp, err := client.Get(url)
459 if err == nil {
460 _ = resp.Body.Close()
461 return nil
462 }
463 t.Logf("Server not ready yet: %s", err)
464 }
465 }
466}
467
468func waitAgentAPIStable(ctx context.Context, t testing.TB, apiClient *agentapisdk.Client, waitFor time.Duration, msg string) error {
469 t.Helper()

Callers 1

setupFunction · 0.85

Calls 2

CloseMethod · 0.80
StopMethod · 0.45

Tested by

no test coverage detected