Skip to content

Improved MySQL acceptance test resets#28554

Merged
9larsons merged 3 commits into
mainfrom
codex/core-mysql-acceptance-reset-snapshot
Jun 12, 2026
Merged

Improved MySQL acceptance test resets#28554
9larsons merged 3 commits into
mainfrom
codex/core-mysql-acceptance-reset-snapshot

Conversation

@9larsons

@9larsons 9larsons commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Cache the initialized MySQL acceptance-test database into in-database snapshot tables after the first truncating reset.
  • Restore subsequent MySQL resets from that snapshot instead of rerunning knexMigrator.init({only: 3}) for every Ghost boot.
  • Invalidate and clean snapshot tables when using the full reset/teardown paths, with fallback to the existing slow-safe reinitialization path.
  • Move the older e2e-utils boot helper onto the truncating reset path so it benefits from the same reset behavior.

Local runtime data

Initial profiling showed the MySQL suite was spending most of its time in reset lifecycle rather than Ghost boot:

  • Baseline full local MySQL E2E profile: 136 modern framework resets took 155.0s total; modern Ghost boot was only 9.6s total.
  • With this change, full local MySQL E2E: 136 modern framework resets took 6.5s total.
  • The older e2e-utils path also improved locally because it now uses the truncating reset path.

Validation

  • pnpm --dir ghost/core lint:test
  • MySQL admin acceptance bucket: 967 passing; framework reset total 3.9s across 85 boots; knexMigrator.init count 5; wall clock 107.3s
  • MySQL full core E2E acceptance suite: 1681 passing, 2 pending; framework reset total 6.5s across 136 boots; wall clock 170.0s
  • SQLite full core E2E acceptance suite: 1682 passing, 1 pending; wall clock 110.5s

Notes

  • The e2e-utils.js change moves every legacy MySQL e2e boot from a full knexMigrator.reset + init to the truncating reset path. The behavioral difference: a full reset drops stray tables and repairs schema drift, while the truncate path only deletes rows from schemaTables + migrations. The full-suite runs above cover this, and the line is severable from the snapshot work if it ever causes flakiness.

no ref

The MySQL acceptance suite was spending most of its time rerunning fixture initialization for every Ghost boot. Restoring test data from an in-database baseline keeps the same reset coverage while avoiding repeated knex-migrator init work.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08e43758-438e-4f34-9480-71e65d408419

📥 Commits

Reviewing files that changed from the base of the PR and between 15492f4 and 59aa7ca.

📒 Files selected for processing (1)
  • ghost/core/test/utils/db-utils.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • ghost/core/test/utils/db-utils.js

Walkthrough

This PR adds MySQL snapshot functionality to test database utilities for faster reset operations. A new mysqlSnapshotDatabase variable tracks snapshot state. Internal helpers implement snapshot creation by copying tables and restoration via transaction-wrapped restores with foreign key handling. The reset() method attempts snapshot restore on MySQL, falling back to full reinitialization and new snapshot creation on failure. The teardown() method now drops snapshot tables and invalidates state in both success and error paths. The e2e test startup helper is updated to use the snapshot-enabled reset method. The truncateAll utility is refactored to use a shared reset-tables helper.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improved MySQL acceptance test resets' directly and clearly describes the main change—optimizing MySQL test database resets using snapshot caching.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the snapshot-based reset optimization, performance improvements, and validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/core-mysql-acceptance-reset-snapshot

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 12, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 3e9b83b

Command Status Duration Result
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 1m 46s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 1m 6s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 3m 49s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 3m 44s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 2m 14s View ↗
nx run-many -t lint -p ghost ✅ Succeeded 41s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 32s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-12 16:46:34 UTC

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
ghost/core/test/utils/db-utils.js (1)

75-79: ⚡ Quick win

Log snapshot restore failures before fallback.

Line 75 catches restore errors and immediately falls back, but drops the original failure context. Adding a debug log here will make intermittent MySQL reset failures much easier to diagnose.

Suggested patch
         try {
             await resetMySQLFromSnapshot();
         } catch (err) {
+            debug('MySQL snapshot reset failed, falling back to force reinit', err);
             // If it fails, try a normal restore
             await forceReinit();
             await createMySQLSnapshot();
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/test/utils/db-utils.js` around lines 75 - 79, The catch block that
falls back to a normal restore currently swallows the original error; update the
catch handler to log the caught error (err) before calling forceReinit() and
createMySQLSnapshot() so we preserve failure context for debugging. Locate the
try/catch around the snapshot restore in db-utils.js and add a debug/error log
call that includes a clear message plus the err object (reference the existing
catch variable `err` and the surrounding functions `forceReinit` and
`createMySQLSnapshot`) so intermittent MySQL reset failures are recorded prior
to the fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ghost/core/test/utils/db-utils.js`:
- Around line 75-79: The catch block that falls back to a normal restore
currently swallows the original error; update the catch handler to log the
caught error (err) before calling forceReinit() and createMySQLSnapshot() so we
preserve failure context for debugging. Locate the try/catch around the snapshot
restore in db-utils.js and add a debug/error log call that includes a clear
message plus the err object (reference the existing catch variable `err` and the
surrounding functions `forceReinit` and `createMySQLSnapshot`) so intermittent
MySQL reset failures are recorded prior to the fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a526d410-eb65-49f5-8724-c929cb73e6ca

📥 Commits

Reviewing files that changed from the base of the PR and between e0a2907 and 15492f4.

📒 Files selected for processing (2)
  • ghost/core/test/utils/db-utils.js
  • ghost/core/test/utils/e2e-utils.js

9larsons added 2 commits June 12, 2026 11:19
- folded snapshot-state invalidation into dropMySQLSnapshots so dropping
  and invalidating can never drift apart at call sites
- hoisted the snapshot cleanup out of teardown's try/catch since both
  branches ran the identical drop + invalidate pair
@9larsons 9larsons enabled auto-merge (squash) June 12, 2026 16:45
@9larsons 9larsons merged commit be948e9 into main Jun 12, 2026
32 checks passed
@9larsons 9larsons deleted the codex/core-mysql-acceptance-reset-snapshot branch June 12, 2026 16:46
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