Skip to content

test: share the aws_accounts and aws_connect_sessions fixture tables - #173

Merged
GoddeyUwamari merged 1 commit into
mainfrom
aws-fixtures/shared-accounts-sessions
Oct 5, 2026
Merged

GoddeyUwamari merged 1 commit into
mainfrom
aws-fixtures/shared-accounts-sessions

Conversation

@GoddeyUwamari

Copy link
Copy Markdown
Owner

Description

Test-only change. No production code, migration, schema or CI workflow is touched.

The race. Six backend suites each created aws_accounts (and two of them aws_connect_sessions) when the table was missing, then dropped whatever they had created in afterAll. Jest runs suites in parallel workers against one database, so a suite finishing first could drop a table another suite was still using. This is the same pattern #171 removed for api_keys and sso_configurations.

The change. Both tables move into backend/src/routes/__tests__/shared-fixture-tables.ts and follow its existing pattern: CREATE TABLE IF NOT EXISTS inside a transaction holding pg_advisory_xact_lock, client released in finally. No suite drops either table any more. Each suite deletes only rows for the organizations it created.

Definitions. Before moving anything, every suite's CREATE TABLE was compared after whitespace normalisation:

Table Suites defining it Distinct definitions
aws_accounts 6 1
aws_connect_sessions 2 1

The helper carries those definitions unchanged (same columns, types, defaults, primary keys and the two named unique constraints on aws_accounts). .github/scripts/ci-bootstrap-schema.js defines neither table, so there was nothing to reconcile against it.

Affected suites

  • routes/__tests__/aws-connection-funnel-event.test.ts
  • routes/__tests__/aws-connection-api-key-authorization.test.ts
  • services/__tests__/system-intelligence.service.cost-score.test.ts
  • services/__tests__/aws-cost-freshness.test.ts
  • services/__tests__/cloudwatch.service.fleet-pagination.test.ts
  • services/__tests__/cloudwatch.service.concurrency.test.ts

One behavioural note: aws-connection-funnel-event.test.ts previously relied on the table drop to clear its rows. It now deletes its own aws_accounts / aws_connect_sessions rows by organization id.

Verification

All runs used a fresh local database built with .github/scripts/ci-bootstrap-schema.js (48 migrations; both tables absent afterwards). Local Postgres is 15; CI uses 14.

  • Each suite alone, tables dropped first: 6/6 suites pass (68 tests).
  • All six concurrently, --maxWorkers=6, 8 rounds, both tables dropped before every round: 8/8 rounds pass, 6 suites / 68 tests each. No relation ... does not exist, no duplicate-key or constraint errors, and 0 rows left in either table after every round.
  • Helper under concurrent invocation: 24 separate sessions calling the helper for both tables at once, 20 rounds with the tables dropped before each: 960 calls, 0 rejected, all clients returned to their pools. The same load with a bare CREATE TABLE IF NOT EXISTS and no lock rejected 460 of 960 calls (pg_type_typname_nsp_index), which is the failure the lock prevents.
  • tsc --noEmit (backend): clean.
  • Full backend suite, --maxWorkers=4: 186 of 187 suites pass, 3014 of 3016 tests. The two failures are both in services/__tests__/migrate-deploy.test.ts ("Case F" symlink cases). That suite runs a shell script and uses no database; it fails the same way when run on its own and is not touched here.

Type of Change

  • Bug fix (test reliability)

Checklist

  • Self-review completed
  • Only the shared fixture helper and the six suites above changed

🤖 Generated with Claude Code

Six backend suites each created these tables when missing and dropped
them on the way out. Suites run in parallel workers against one
database, so one suite's teardown could remove a table another suite
was still using.

Both tables now come from the shared fixture helper, which creates them
under a transaction-scoped advisory lock and never drops them. Every
suite's definition was identical, so the helper carries that definition
unchanged. Each suite deletes only the rows it created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
devcontrol Ready Ready Preview Oct 5, 2026 1:22pm UTC

@GoddeyUwamari
GoddeyUwamari merged commit ea4942e into main Oct 5, 2026
6 checks passed

This branch was successfully deployed

1 active deployment
Preview — 6e47b6d6 Deployed Oct 5, 2026 by vercel[bot]
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