Commit Graph
2 Commits
Author SHA1 Message Date
Cian Johnston 3052089c4d test: fix transport error flake (#26132)
`TestResolveWorkspace/TransportError` could sometimes observe an HTTP
404 from a closing test server instead of a transport error.

Make the test deterministic by injecting a failing `http.RoundTripper`,
and add `testutil.RoundTripperFunc` for reuse.

Generated by Coder Agents.

<details>
<summary>Implementation plan</summary>

# Plan: Deterministic ResolveWorkspace transport error test

## Context

`TestResolveWorkspace/TransportError` relied on closing an
`httptest.Server` before making a request. CI showed this can race with
the request path and produce an HTTP 404 instead of a transport error.
The test should inject a transport failure directly.

## Red

1. Update the transport-error case to use a custom `http.RoundTripper`
that returns an error.
2. Confirm the test fails to compile until the reusable
`testutil.RoundTripperFunc` helper exists.

## Green

1. Add `testutil.RoundTripperFunc` in `testutil/http.go`.
2. Implement `RoundTrip` so the function type satisfies
`http.RoundTripper`.
3. Add a compile-time interface assertion for the helper.
4. Update `codersdk/workspaces_test.go` to inject a client using
`testutil.RoundTripperFunc`.
5. Keep the existing assertion that transport errors do not become
`*codersdk.Error`.

## Refactor

1. Run `gofmt` on touched Go files.
2. Check import cleanup and variable names after the implementation
compiles.
3. Keep the change limited to the reusable helper and this test.

## Verification

1. `go test ./codersdk -run TestResolveWorkspace -count=100`
2. `go test ./testutil ./codersdk -run TestResolveWorkspace -count=1`
3. `git diff --check`

</details>
2026-06-08 15:11:36 +01:00
Thomas Kosiewski 6fb4cc6b82 fix: add retry logic to OAuth2 metadata tests to avoid race conditions (#19813)
This PR adds a readiness wait to OAuth2 metadata endpoint tests to avoid rare races with server startup. Instead of immediately making HTTP requests, the tests now use `testutil.Eventually` to retry the requests until they succeed, with a short interval between attempts. This helps prevent flaky tests that might fail due to timing issues during server initialization.  
  
Fixes: https://github.com/coder/internal/issues/996
2025-09-22 18:30:36 +02:00