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

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

Analyze Your Own Codebase

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

Try Supermodel Free