EnsureLocalHTTPContent will verify a URL responds with a 200, expected content string, and optional parameters. Parameters can be either: - HTTPRequestOpts struct with TimeoutSeconds and MaxRetries fields - int representing timeout seconds (for backward compatibility)
(t *testing.T, rawurl string, expectedContent string, params ...any)
| 582 | // - HTTPRequestOpts struct with TimeoutSeconds and MaxRetries fields |
| 583 | // - int representing timeout seconds (for backward compatibility) |
| 584 | func EnsureLocalHTTPContent(t *testing.T, rawurl string, expectedContent string, params ...any) (*http.Response, error) { |
| 585 | options := parseHTTPRequestOpts(40, params...) |
| 586 | assert := asrt.New(t) |
| 587 | |
| 588 | body, resp, err := GetLocalHTTPResponse(t, rawurl, options) |
| 589 | // We see intermittent php-fpm SIGBUS failures, only on macOS. |
| 590 | // That results in a 502/503. If we get a 502/503 on macOS, try again. |
| 591 | // It seems to be a 502 with nginx-fpm and a 503 with apache-fpm |
| 592 | if nodeps.IsMacOS() && resp != nil && (resp.StatusCode >= 500) { |
| 593 | t.Logf("Received %d error on macOS, retrying GetLocalHTTPResponse", resp.StatusCode) |
| 594 | time.Sleep(time.Second) |
| 595 | body, resp, err = GetLocalHTTPResponse(t, rawurl, options) |
| 596 | } |
| 597 | assert.NoError(err, "GetLocalHTTPResponse returned err on rawurl %s, resp=%v, body=%v: %v", rawurl, resp, body, err) |
| 598 | assert.Contains(body, expectedContent, "request %s got resp=%v, body:\n========\n%s\n==========\n", rawurl, resp, body) |
| 599 | return resp, err |
| 600 | } |
| 601 | |
| 602 | // CheckGoroutineOutput makes sure that goroutines |
| 603 | // aren't beyond specified level |