Home / Function/ waitForServerReady() — gin Function Reference

waitForServerReady() — gin Function Reference

Architecture documentation for the waitForServerReady() function in test_helpers.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  bdf7df80_3209_9ea6_1fe4_ccd217942ce5["waitForServerReady()"]
  ef0ce555_e7e9_3369_e666_6c8470156eda["test_helpers.go"]
  bdf7df80_3209_9ea6_1fe4_ccd217942ce5 -->|defined in| ef0ce555_e7e9_3369_e666_6c8470156eda
  style bdf7df80_3209_9ea6_1fe4_ccd217942ce5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

test_helpers.go lines 39–60

func waitForServerReady(url string, maxAttempts int) error {
	client := &http.Client{
		Timeout: 100 * time.Millisecond,
	}

	for i := 0; i < maxAttempts; i++ {
		resp, err := client.Get(url)
		if err == nil {
			resp.Body.Close()
			return nil
		}

		// Exponential backoff: 10ms, 20ms, 40ms, 80ms, 160ms...
		backoff := time.Duration(10*(1<<uint(i))) * time.Millisecond
		if backoff > 500*time.Millisecond {
			backoff = 500 * time.Millisecond
		}
		time.Sleep(backoff)
	}

	return fmt.Errorf("server at %s did not become ready after %d attempts", url, maxAttempts)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does waitForServerReady() do?
waitForServerReady() is a function in the gin codebase, defined in test_helpers.go.
Where is waitForServerReady() defined?
waitForServerReady() is defined in test_helpers.go at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free