## TL;DR
`TestAcquirer_MatchTags` sometimes fails with `context deadline
exceeded` before it checks anything. The test started its 10 second
deadline first and created its test database second. When the database
took 10 seconds or more to create, the deadline had already passed by
the time the test ran its first query. This PR starts the deadline after
the database exists, so slow database setup no longer fails the test.
Refs
https://linear.app/codercom/issue/CORE-713/flake-testacquirer-matchtagsuser-scoped-provisioner-and-user-scoped
<details>
<summary>How to navigate this PR</summary>
- One test file, no production code.
- Read `coderd/provisionerdserver/acquirer_test.go`, inside the subtest
loop of `TestAcquirer_MatchTags`. One line moves below
`dbtestutil.NewDB`, and a two-line comment says why.
</details>
<details>
<summary>Implementation</summary>
- `coderd/provisionerdserver/acquirer_test.go`: the `testutil.Context(t,
testutil.WaitShort)` line in `TestAcquirer_MatchTags` now comes after
`dbtestutil.NewDB(t)`.
- Nothing between the old and the new position uses the context, so what
the test checks is unchanged.
- `TestAcquirer_Store` in the same file already creates its database
first.
- The deadline is not made longer. A longer deadline would only make the
failure less likely, because database setup has no upper limit that a
fixed value could cover.
- Other tests in the repository create a short deadline before
`dbtestutil.NewDB` in the same way. They are left for a separate change.
</details>
<details>
<summary>Expected Output</summary>
- When creating the test database takes longer than 10 seconds, every
`TestAcquirer_MatchTags` subtest still passes.
- The test still gives each subtest 10 seconds for the part that checks
tag matching.
- A subtest with a wrong expectation still fails. A provisioner that
should not get a job, but is expected to, fails at the `AcquireJob`
assertion when the deadline ends.
</details>
<details>
<summary>Testing</summary>
- No test was added. The change is to the test itself.
- The recorded failure: `test-go-pg (windows-2022)` in the nightly
workflow, [job
111783661367](https://github.com/coder/coder/actions/runs/37316261411/job/111783661367).
The subtest failed at its first insert in the same millisecond the
pubsub became ready, after 10 to 14.6 seconds of setup.
- Reproduced on `main` on macOS with a local PostgreSQL 17. In a run of
20 repeats with `-parallel=16`, 16 subtests failed at the same line with
the same message. They were exactly the 16 whose database copy took over
10 seconds.
- With a temporary 10.5 second delay before database creation in every
subtest (not part of this PR):
- `main`: 42 of 42 database subtests failed at the same line.
- This change: 44 of 44 subtests passed.
- This change without the delay: 20 repeats passed, 440 of 440 subtests.
- Mutation check: with the expectation of one "no match" case set to
"match", that subtest failed at the `AcquireJob` assertion.
- On this branch: `go test ./coderd/provisionerdserver -run
'^TestAcquirer_' -count=3 -parallel=16` passes.
- Not covered: the Windows and macOS lanes run only in the nightly
workflow, so they have not run on this branch yet.
</details>