Skip to content

Add integration tests for PgmqTransport against a real pgmq - #8

Open
iGrog wants to merge 4 commits into
thesis-php:0.5.xfrom
iGrog:test/pgmq-transport-integration
Open

iGrog wants to merge 4 commits into
thesis-php:0.5.xfrom
iGrog:test/pgmq-transport-integration

Conversation

@iGrog

@iGrog iGrog commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2, #3.

The PGMQ transport had no tests. This PR adds:

  • a pgmq service to compose.yaml (ghcr.io/pgmq/pg18-pgmq:v1.11.1, the same image thesis/pgmq uses) and THESIS_PGMQ_DSN for the php service. make test already runs up, so the CI needs no changes;
  • PgmqTransportTest::consumerDrainsBacklogWithoutWaitingForPollInterval;
  • PgmqNotifyTriggerTest:
    • consumerStartDoesNotWaitForProducerTransactions: notifications set up, a producer keeps an insert open, the start must not wait;
    • concurrentConsumerStartsCreateTheTriggerOnce: 4 workers (separate pools, like worker processes) start at once on a queue without notifications, while an open producer transaction forces the starts to overlap; CREATE TRIGGER is counted with an event trigger and must be exactly 1, with no failed starts;
    • consumerStartRestoresNotificationsLostInCrashRecovery: the queue's row in the UNLOGGED pgmq.notify_insert_throttle is removed (what crash recovery does), and a start must bring notifications back;
    • consumerStartRestoresDisabledTrigger;
    • createdQueueWakesConsumerOnInsert: createQueue() sets notifications up.
  • the one-line phpstan fix from Remove the @phpstan-ignore that no longer matches #5, so the run shows only the tests' own result.

Whether the package's dev environment should include Postgres is your call. That is why the fixes (#6, #7) are separate PRs that do not depend on this one.

Expected CI result

The event-trigger test needs a superuser connection, which the compose service provides.

Adds a pgmq service to compose.yaml (THESIS_PGMQ_DSN) and the first PgmqTransport
tests: a backlog must drain without waiting for the poll interval, a consumer start
must not wait for open producer transactions, and createQueue() must set up insert
notifications.
iGrog added 3 commits October 7, 2026 13:46
pgmq.notify_insert_throttle is UNLOGGED: crash recovery (or a promoted replica) empties
it, and the insert trigger then never notifies. The test removes the queue's row and
expects a consumer (re)start to bring notifications back.
Recent PHPStan 2.2.x infers the nested property assignment correctly, so the ignore
is unmatched and phpstan fails on every cell of the CI matrix (8.4/8.5 x lowest/highest).

(cherry picked from commit ec45573)
- 4 consumers (separate pools, like worker processes) starting at once on a queue
  without notifications create the trigger exactly once (counted with an event trigger);
- a consumer start restores a disabled trigger.
@iGrog

iGrog commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated the tests:

  • new concurrentConsumerStartsCreateTheTriggerOnce (event trigger counts CREATE TRIGGER; 4 workers with separate pools; collects start failures so they don't leak into other tests);
  • new consumerStartRestoresNotificationsLostInCrashRecovery and consumerStartRestoresDisabledTrigger;
  • the phpstan fix from Remove the @phpstan-ignore that no longer matches #5.

On 0.5.x exactly 3 tests fail, one per defect. With #6, #7 and thesis-php/pgmq#22 all 14 pass (verified locally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant