Skip to content

fix(auth): the database tests pass on a busy machine without timing out - #709

Draft
PiquelChips wants to merge 2 commits into
mainfrom
fix/708-db-tests-under-load
Draft

PiquelChips wants to merge 2 commits into
mainfrom
fix/708-db-tests-under-load

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

On a busy machine, a full just db test failed a different handful of tests each run. Almost every failure had one cause. The signing key tests hold the database-wide signing key lock while they generate several 3072-bit RSA keys. Every replica that any test starts waits for that same lock, under the 15-second statement limit. Under load, key generation took longer than that, so tests that never touch signing keys failed as they started.

What changed: only test fixtures and test files. Production code and its time limits are unchanged, and no test is skipped or weakened: all 509 tests run, as before.

  • A test that holds a database-wide lock gets a database of its own. Database::isolated now creates a database rather than a schema, because advisory locks are per database. The signing key tests, the admin signing key test and the dashboard's rotate-and-revoke test use it. The audit tests already did, so each now has its own audit locks. Creating the database has no statement limit, on its setup connection only, since copying the template database can take longer on a loaded disk.

  • The signing-keys and audit test groups are gone. Their tests no longer share a lock with each other.

  • Waits that only set a test up are long enough for a loaded machine. These waits are setup, not what the test checks:

    • Test pools wait up to a minute for a connection, which also bounds connecting for migrations: Database::TEST_ACQUIRE_TIMEOUT, through one Database::test_config. The PoolTimedOut and "migrate: timed out" failures were this.
    • The audit tests wait up to two minutes for their events to be sealed. Sealing waits for every older transaction on the server, in any database.
    • operators_retry_and_cancel_deliveries uses a 5-second lease instead of 300 ms. The lease is a window the test picks, not a limit.

    The one test that asserts the service's 5-second pool wait keeps it.

  • No concurrency cap: connections never ran short. At the default 16 threads, the cluster peaked at 89–120 client connections of its 400, so test-threads stays at the default.

docs/dev/testing.md now says when a test needs a database of its own, which waits a test may lengthen, and how to drop the test_ databases a run leaves on a server of your own.

Proof: each run is the full suite at the default thread count in a fresh scratch cluster, on a 16-core machine. The load is CPU-bound busy loops running beside it, plus whatever other agents were running.

Load Load average origin/main This branch
32–64 loops 36–76 2 of 2 runs failed (13 and 4 tests), all on the signing key lock 6 of 6 in a row passed, median 47–77, the last one a full just db test with the query-cache check
128 loops 134–169 101 failed: 96 on the signing key lock, 3 audit seal deadlines, 2 keys tests 1 of 3 runs failed one test; see below

What's left

  • A keys test can still fail at a load average of 130 to 170, in about 1 run of 3. It generates an RSA key inside its transaction, as rotation does in production. When the test process gets a few percent of a CPU, that takes over 30 seconds, so PostgreSQL ends the session as idle in a transaction. That 30-second limit is the service's own, so it stays.
  • The issue's lock-wait failures weren't reproduced. invitation_revocation_waits_for_signup, revoked_invitations_cannot_be_redeemed and mutations_recheck_the_confirmation_after_waiting passed in every run here, and they're unchanged.

just validate passes except just audit. It fails on RUSTSEC-2026-0592 in url 2.5.8, which is also on main, and #707 fixes it. just docs passes.

Refs #708

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 (via T3 Code)

Tests that hold the signing key lock while they generate keys work in a
database of their own, so the replicas other tests start no longer time out
waiting for it. Database::isolated creates a database rather than a schema,
since advisory locks are per database, so the signing-keys and audit test
groups are no longer needed. Test pools wait up to a minute for a connection,
the audit tests up to two minutes for sealing, and one delivery test's lease
is long enough for a loaded machine. Production limits are unchanged.

Closes #708
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 22, 2026
…limit

Also says how to drop the test_ databases a run leaves on a server of your
own, and that TEST_DATABASE_URL must never name a server that matters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant