Skip to content

test(tenants/pg): the cached-tenant test stops the invalidation listener before the database goes - #337

Merged
CMGS merged 1 commit into
mainfrom
fix/pg-cache-test-listener
Oct 7, 2026
Merged

CMGS merged 1 commit into
mainfrom
fix/pg-cache-test-listener

Conversation

@CMGS

@CMGS CMGS commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

TestACachedTenantOutlivesTheDatabase failed on #336's first CI run with a cached tenant with the database gone: <nil> tenant store down: closed pool, and passed on the re-run.

The invalidation listener evicts the cache on its first connect (synced) and again when the test's Put commits with its NOTIFY. Both run after Open returns, on the listener's schedule. The test read the cache as populated, closed the pool, and one of those evictions landed in between, so the next Resolve missed the cache and reached the closed pool.

The case the test proves, a cached tenant outliving a database outage, has no live listener either: while the database is down the listener cannot reconnect, and a reconnect is what flushes the cache. The test now stops the listener before it fills the cache and closes the pool, so nothing can evict between the two steps.

Evidence against a throwaway postgres:17: the old test fails 2 of 40 runs with the CI message; the new one passes 20 of 20 under -race, and tenants/pg + poolset/pg pass 3 times with no skip. Lint, fmt and asl clean on the package.

…ner before the database goes

The listener evicts the cache on its first connect and again on the Put's
NOTIFY, both after Open returns and on their own schedule. The test read
the cache as populated, closed the pool, and then one of those evictions
landed, so Resolve went to the closed pool. The database-down case it
proves has no live listener either, so the test stops it first; the old
version failed 2 of 40 runs locally with the CI message.
@CMGS
CMGS merged commit 3537a6e into main Oct 7, 2026
1 check passed
@CMGS
CMGS deleted the fix/pg-cache-test-listener branch October 7, 2026 02: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