Files
coder/coderd/coderdtest
Thomas Kosiewski b61ec4395e fix(coderd/coderdtest): read the swagger doc once in TestSwaggerEnumsNotNarrowed (#32065)
## Why

The `test-go-race-pg` job fails intermittently with `WARNING: DATA RACE`
in `swag.(*Spec).ReadDoc`, on pull requests whose changes do not cause
it. It failed CI runs 43102680650 and 43103681536 on two unrelated pull
requests. A green rerun of the same commit passes, so it hides as a
flake.

## Cause

swag's `Spec.ReadDoc` writes shared state, so parallel tests that each
call it race. #31829 addressed this by reading the spec once through
`swaggerDoc`, a `sync.OnceValue`. #30122 then added
`TestSwaggerEnumsNotNarrowed` with a direct
`apidoc.SwaggerInfo.ReadDoc()` call, which races with the tests that
still read the shared value.

## What changed

`TestSwaggerEnumsNotNarrowed` calls `swaggerDoc()`, like the other
tests. It was the only direct call outside the generated
`coderd/apidoc/docs.go`.

## Reproduction

- On `main` (412d998777), `go test -race -count=20 -run
'TestSwagger|TestChatModelPathParametersFormatted' ./coderd/coderdtest/`
fails with 2 data race reports. `TestChatModelPathParametersFormatted`,
`TestSwaggerParametersValid` and `TestSwaggerEnumsNotNarrowed` fail.
- With this change, the same command passes with no data race report.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
2026-11-11 23:50:14 +01:00
..
…
…