Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds lifecycle cleanup for temporary MySQL schemas used by integration tests.
Changes:
- Adds schema teardown and orphan sweeping.
- Exports the teardown helper.
- Updates 12 integration suites to drop temporary schemas.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
libs/shared/db/mysql/account/src/lib/tests.ts |
Adds schema cleanup logic. |
libs/shared/db/mysql/account/src/index.ts |
Exports teardown helper. |
libs/shared/account/account/src/lib/account.manager.in.spec.ts |
Uses teardown helper. |
libs/payments/stripe/src/lib/accountCustomer/accountCustomer.repository.in.spec.ts |
Uses teardown helper. |
libs/payments/stripe/src/lib/accountCustomer/accountCustomer.manager.in.spec.ts |
Uses teardown helper. |
libs/payments/paypal/src/lib/paypalCustomer/paypalCustomer.repository.in.spec.ts |
Uses teardown helper. |
libs/payments/paypal/src/lib/paypalCustomer/paypalCustomer.manager.in.spec.ts |
Uses teardown helper. |
libs/payments/cart/src/lib/checkout.service.in.spec.ts |
Uses teardown helper. |
libs/payments/cart/src/lib/cart.manager.in.spec.ts |
Uses teardown helper. |
libs/accounts/two-factor/src/lib/backup-code.manager.in.spec.ts |
Cleans each per-test schema. |
libs/accounts/recovery-phone/src/lib/recovery-phone.manager.in.spec.ts |
Uses teardown helper. |
libs/accounts/passkey/src/lib/passkey.security.in.spec.ts |
Uses teardown helper. |
libs/accounts/passkey/src/lib/passkey.repository.in.spec.ts |
Uses teardown helper. |
libs/accounts/passkey/src/lib/passkey.manager.in.spec.ts |
Uses teardown helper. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+113
to
+115
| HAVING MAX(CREATE_TIME) < NOW() - INTERVAL ${sql.lit( | ||
| ORPHAN_SCHEMA_MAX_AGE_HOURS | ||
| )} HOUR |
| afterAll(async () => { | ||
| await clearRedisSmsKeys(); | ||
| await db.destroy(); | ||
| await testAccountDatabaseTeardown(db); |
Comment on lines
+79
to
+83
| try { | ||
| const name = await currentSchema(db); | ||
| if (name?.startsWith(TEST_SCHEMA_PREFIX)) { | ||
| await sql`DROP DATABASE IF EXISTS ${sql.table(name)}`.execute(db); | ||
| } |
## Because - `testAccountDatabaseSetup` creates a `testAccount-<uuid>` schema for each spec file and never drops it. Closing the pool does not drop a schema. - A local MySQL gains one schema per spec file per run. One developer machine held 184 of them before anyone noticed. CI is not affected. ## This pull request - Adds `testAccountDatabaseTeardown(db?)` to `tests.ts` and exports it. The helper reads its own schema with `SELECT DATABASE()`. It drops that schema only when the name starts with `testAccount-`, then closes the pool in a `finally`. - Calls the teardown from `afterAll` in the 12 `.in.spec.ts` files that call the setup. Jest runs `afterAll` for failing runs too, so those runs also clean up. - Sweeps `testAccount-*` schemas older than 3 hours at the start of the setup, from `information_schema.TABLES.CREATE_TIME`. This covers a crash or a Ctrl-C, where no hook runs. The sweep is age based, so a concurrent run keeps its schema. - Moves the hook in `backup-code.manager.in.spec.ts` to `afterEach`. That file calls the setup in `beforeEach`, so `afterAll` still left four schemas per run. - Adds `tests.spec.ts`, a unit spec for the `testAccount-` guard. It mocks the `kysely` `sql` tag, so the spec needs no MySQL. ## Issue that this pull request solves Closes: https://mozilla-hub.atlassian.net/browse/FXA-14412
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because
testAccountDatabaseSetupcreates atestAccount-<uuid>schema for each spec file and never drops it. Closing the pool does not drop a schema.This pull request
testAccountDatabaseTeardown(db?)totests.tsand exports it. The helper reads its own schema withSELECT DATABASE(). It drops that schema only when the name starts withtestAccount-, then closes the pool in afinally.afterAllin the 12.in.spec.tsfiles that call the setup. Jest runsafterAllfor failing runs too, so those runs also clean up.testAccount-*schemas older than 3 hours at the start of the setup, frominformation_schema.TABLES.CREATE_TIME. This covers a crash or a Ctrl-C, where no hook runs. The sweep is age based, so a concurrent run keeps its schema.backup-code.manager.in.spec.tstoafterEach. That file calls the setup inbeforeEach, soafterAllstill left four schemas per run.tests.spec.ts, a unit spec for thetestAccount-guard. It mocks thekyselysqltag, so the spec needs no MySQL.Issue that this pull request solves
Closes: https://mozilla-hub.atlassian.net/browse/FXA-14412
Checklist
Put an
xin the boxes that applyHow to review (Optional)
DROP DATABASEpaths intests.ts. Both check thetestAccount-prefix.tests.ts, thentests.spec.ts, then the spec file hooks.Screenshots (Optional)
Other information (Optional)
Round 2 reorders the
afterAllinrecovery-phone.manager.in.spec.ts. The Redis cleanup ran first. A Redis failure therefore skipped the teardown and leaked the schema and the pool. The database teardown now runs first. The other 11 files already call it first.nx test-unit shared-db-mysql-account: 8 passed, 0 failed.nx test-integration accounts-recovery-phone: 16 passed, 0 failed. NotestAccount-%schema was left behind.