`tasks_test.go` kept its own copy of the recording pubsub,
`taskRecordingPubsub` (59 lines), next to `recordingPubsub` in
`helpers_test.go`. This PR adds the three things the copy had (`clear`,
a `published` snapshot and an `onPublish` hook) to `recordingPubsub`,
points the task fixture at it, and deletes the copy. The task fixture
now reaches the raw pubsub through the embedded field, so its `rawPS`
field goes too.
**Why it is safe**
- The added methods behave like the copy's: `onPublish` runs outside the
lock and before the inner `Publish`, `clear` drops the recorded events,
and `published` returns a copy taken under the lock. It replaces the
copy's `events()`, which would collide with the existing `events` field.
- `recordingPubsub` embeds the full `dbpubsub.Pubsub`, so subscriptions
reach the same inner pubsub the copy forwarded `SubscribeWithErr` to.
Servers built by the task helpers still get the raw pubsub.
- `watchEvents` is the existing `recordingPubsub` method. It filters the
same way the copy did, reading under the lock instead of from a
snapshot.
- After the change, `rg 'taskRecordingPubsub|taskPublishedEvent|rawPS'
coderd/` finds nothing.
**Review focus**
The turn-trace tests set `f.pubsub.onPublish` while holding
`f.pubsub.mu`. Both names are unchanged, and `Publish` still reads the
hook under that lock.
**Validation**
I built the package test binary with `go test -c ./coderd/x/chatd/` (and
with `-race`). Ten files use either fixture: `tasks_test.go`,
`hooks_internal_test.go`, `turn_trace_internal_test.go` and the seven
`workerTestFixture` files. I ran the 142 top-level tests in the ten
files with `-test.count=1 -test.parallel 4`.
| Head | Plain | `-race` |
|---|---|---|
| `main` (`e289c6fe011`) | 142 passed | 142 passed, no data races |
| this PR | 142 passed | 142 passed, no data races |
The pre-commit hook passed.
**Stack**
The stack folds the task test fixture into the shared worker test
fixture.
1. #30923 reuse `recordingPubsub` in the task test fixture (this PR)
2. #30924 fold `taskTestFixture` into `workerTestFixture`
> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.