{"record":{"id":"26211ddb113868f4","repo":"grafana/k6","slug":"fetching-test-status-w","errorCode":null,"errorMessage":"fetching test status: %w","messagePattern":"fetching test status: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/api.go","lineNumber":144,"sourceCode":"\n// WaitForTestRunReady polls GET /cloud/v6/test_runs/{id} until the\n// backend status becomes \"initializing\" (signalling that k6 can begin\n// local execution). Returns an error if the test run reaches \"aborted\"\n// or \"completed\" first. Cancellable via context. Logs status transitions\n// at Debug level once per change.\n//\n// If pollInterval is <= 0 the defaultWaitPollInterval is used.\nfunc (c *Client) WaitForTestRunReady(ctx context.Context, testRunID int64, pollInterval time.Duration) error {\n\tif pollInterval <= 0 {\n\t\tpollInterval = defaultWaitPollInterval\n\t}\n\n\tvar lastStatus string\n\n\tfor {\n\t\tprogress, err := c.v6Client.FetchTest(ctx, testRunID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"fetching test status: %w\", err)\n\t\t}\n\n\t\tstatus := progress.Status.String()\n\n\t\tswitch v6.Status(status) {\n\t\tcase v6.StatusInitializing:\n\t\t\treturn nil\n\n\t\tcase v6.StatusAborted:\n\t\t\tvar abortMsg string\n\t\t\tfor _, e := range progress.StatusHistory {\n\t\t\t\tif e.Status == v6.StatusAborted && e.Message != \"\" {\n\t\t\t\t\tabortMsg = e.Message\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif abortMsg != \"\" {\n\t\t\t\treturn fmt.Errorf(\"test run aborted before starting: %s\", abortMsg)","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cloudapi/provisioning/api.go#L126-L162","documentation":"WaitForTestRunReady (internal/cloudapi/provisioning/api.go:130-148) polls the cloud API (v6Client.FetchTest) every couple of seconds until the provisioned test run reaches 'initializing'. Any failed poll - transport error, 401/403, 404, or exhausted retries - aborts the wait wrapped as 'fetching test status'. k6 never got far enough to start executing; the wrapped error says why the polling died.","triggerScenarios":"Transient network failure or cloud API 5xx during the pre-start polling window; the test run being deleted (404) or the token revoked (401/403) while k6 waits; a backend outage that outlasts the client's retry budget.","commonSituations":"Someone deletes or reconfigures the cloud test run right after provisioning; cloud API blips; expired credentials on long-queued runs.","solutions":["Read the wrapped error for an HTTP status: 401/403 -> fix the cloud token; 404 -> the run was deleted; 5xx/network -> retry the whole run","Re-run the test - a fresh provisioning gets a fresh run ID and polling loop","Check the Grafana Cloud status page if 5xx persists","Avoid deleting/recreating cloud test runs between start_local_execution and execution start"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := client.WaitForTestRunReady(ctx, id, 0); err != nil {\n    if strings.Contains(err.Error(), \"fetching test status\") {\n        // poll failed mid-wait: safe to retry the whole run; a fresh provisioning\n        // gets a new run ID - but first read the wrapped error for 401/403/404\n    }\n}","preventionTips":["Do not delete or recreate cloud test runs between provisioning and execution start","Keep cloud tokens valid for the full run lifecycle including the wait window","Treat repeated 'fetching test status' failures as a cloud API availability signal - check the status page"],"tags":["cloud","network","provisioning","polling","http"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}