Skip to content

Add real-Postgres driver smoke tests + CI job (TODO A5) - #69

Merged
juhovuo merged 2 commits into
mainfrom
feature/pg-smoke-tests
Jul 5, 2026
Merged

juhovuo merged 2 commits into
mainfrom
feature/pg-smoke-tests

Conversation

@juhovuo

@juhovuo juhovuo commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

What

Completes Track A. The -pg packages had zero tests; after #64/#66/#67 all shared SQL is covered by the PGlite suites, leaving only the driver layer uncovered. This adds small real-Postgres smoke suites for core-pg, journal-pg, and digest-pg, plus a pg-smoke CI job.

Details

  • Env-guarded: suites read PG_TEST_URL ?? DATABASE_URL and describe.skip themselves when unset — local pnpm test and the existing check job stay dependency-free (verified: 8 skipped, tasks green).
  • Per-suite DB isolation: each suite creates xjog_<pkg>_smoke_<uuid>, runs the adapter's connect() (migrations) against it, and drops it in afterAll — no node-pg-migrate tracking-table collisions between suites on a shared server. Connection strings are parsed into discrete PoolConfig fields because pg silently ignores a database override when connectionString is present.
  • Coverage: core-pg — connect + migrations, withTransaction commit and rollback, destroyChart; journal-pg + digest-pg — connect + migrations and a real pg-listen → pg_notify LISTEN/NOTIFY round trip each.
  • CI: new pg-smoke job in check-pr.yml with a postgres:16-alpine service container (health-checked), building first (adapters load lib/migrations/*.sql), then running only the three -pg suites serialized. The existing check job is unchanged. turbo.json declares PG_TEST_URL/DATABASE_URL in the test task's env so turbo doesn't serve stale cached results across env changes.

🐛 Real bug found and fixed by these tests

digest-pg's connect() did await pool.connect() and discarded the client without releasing it — permanently occupying a pool slot, so disconnect() → pool.end() hangs forever. Fixed with (await pool.connect()).release(). The hang was reproduced before the fix and confirmed resolved after (the digest suite's teardown is the regression test — it hangs without the fix). Changeset: patch for @telia-oss/xjog-digest-pg.

Verification

All 8 tests run green against real Postgres 16 on two independent local setups (a Homebrew postgres@16 server and a postgres:16-alpine Docker container), including both LISTEN/NOTIFY round trips. Skip path verified with env unset. Full-repo build (15/15) + test (16/16) + lint clean.

Implements TODO item A5 — Track A complete.

juhovuo added 2 commits July 5, 2026 03:49
PGlite covers all SQL for the core/journal/digest Postgres adapters, but
none of the three -pg packages had any test exercising the actual
node-postgres driver: real connection pooling, node-pg-migrate migrations
against a live server, transaction commit/rollback, and LISTEN/NOTIFY.

Add one *.smoke.test.ts per package, wired the same way as the -pglite
packages (jest.config.js + test script). Each suite creates its own
throwaway database in beforeAll and drops it in afterAll so the three
suites' node-pg-migrate migration-tracking tables never collide, and skips
entirely (describe.skip) when PG_TEST_URL/DATABASE_URL isn't set so local
`pnpm test` and the existing CI `check` job stay dependency-free.

Add a `pg-smoke` job to check-pr.yml that runs only these three suites
against a postgres:16-alpine service container.

Fixes found by actually running against real Postgres:
- pg's Pool/Client give `connectionString` priority over a co-supplied
  `database` field, so the per-suite database override was silently
  ignored; the test helper now parses the connection string into discrete
  fields instead.
- turbo's default strict env mode stripped PG_TEST_URL/DATABASE_URL from
  the test task; declared them in turbo.json.
- PostgresDigestPersistenceAdapter.connect() never released the pool
  client it opened to warm the connection, which made pool.end() (and
  therefore disconnect()) hang forever for any real caller.
@juhovuo
juhovuo merged commit 61a815e into main Jul 5, 2026
2 checks passed
@juhovuo
juhovuo deleted the feature/pg-smoke-tests branch July 5, 2026 00:54
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