Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#18501·sequelize

meta: speed up the integration test suites by migrating off the `drop` reset mode, then make `none` the default

Author: wikirik-agentCreated Sep 26, 2026Updated Sep 26, 2026
Labelspending-approval

Context

packages/core/test/integration/support.ts resets the database after every test. The default reset mode is drop: after each test, every table is dropped and every model is unregistered. Next to it is a // TODO: make "none" the default. #15886 tried to flip the default in 2023 but was closed; its description noted that the gain was smaller than expected, and suggested splitting suites and making reset modes dialect-aware.

Today 31 of the 157 integration test files set a reset mode explicitly (14 none, 13 destroy, 8 truncate, 2 drop). The other 126 use the default drop, and 105 of those call sync().

How much time goes to resetting and recreating tables

Integration jobs are most of our CI time. Average durations of the integration test jobs over about 15 recent runs each:

dialect job duration jobs per CI run
oracle latest / oldest 15.3 / 6.0 min 3 + 3
mssql latest 13.0 min 3
db2 latest / oldest 5.2 / 4.6 min 3 + 3
mariadb latest / oldest 3.0 / 2.8 min 3 + 3
mysql latest / oldest 2.1 / 2.5 min 3 + 3
postgres (all variants) 2.0–2.4 min 24
sqlite3 1.0 min 3

Together that is roughly 3.5 hours of job time per CI run.

Profiling test/integration/associations/** locally (SQL time per statement, attributed to tests and hooks) shows that on every dialect with a real server, a large share of the time goes to dropping and recreating tables. Some of it is in the database reset hook. The rest is in sync({ force: true }) calls in tests and beforeEach hooks, which drop and recreate the same tables again.

associations/** (≈280 tests) total SQL in database reset hook DDL (CREATE/DROP/ALTER) dictionary/catalog queries
postgres 26 s 9.4 s (36%) 4.4 s 13.5 s (of which 11.3 s foreign-key lookups)
mysql 41 s 11.5 s (28%) 22.9 s (56%) 6.1 s
oracle (with #18497 + #18498) 82 s 23.9 s (29%) 38.0 s (46%) 23.4 s

MSSQL and DB2 were not profiled locally. Their CI durations (MSSQL is the second-slowest job) suggest the same pattern, since DDL is expensive there as well.

Per-dialect query costs are being addressed separately: #18498 and #18499 (Oracle hard-parsing its dictionary queries, a 3.3× speed-up for the Oracle run above) and #18497 (no foreign-key lookups in dropAllTables when dropping with cascade, which removes 6.5 s of the 9.4 s Postgres reset time above). What remains after those is the amount of DDL the test suites ask for, and that is what this issue is about.

Why flipping the default alone won't help much

In the slowest files, most tests define their own models and call sync({ force: true }) in the test body. For example, associations/belongs-to-many.test.js has 98 tests and 70 sync() calls, about 60 of them inside it() bodies. sync({ force: true }) drops and recreates those tables anyway, so for these files the reset mode barely changes the amount of DDL. With none, tables from earlier tests also stay around, which is risky on dialects that can't drop a table while foreign keys still reference it (e.g. MSSQL and DB2).

The gain comes from restructuring: tests that share a schema should share the tables.

Proposed approach

  1. Migrate the heaviest files first, one PR per file, ordered by measured time across dialects. Starting points: associations/belongs-to-many, associations/belongs-to, associations/has-many, associations/has-one, associations/scope and include. Pattern per file:
    • Group tests that use the same models into a describe block that defines the models and syncs them once in beforeAll2, with setResetMode('destroy') (or 'truncate' where the dialect supports it) to clear only the rows between tests.
    • Move tests that need their own schema (custom FKs, sync({ alter }), table options) into their own describe with setResetMode('drop'), so the exception is explicit.
    • Tests using createSingleTransactionalTestSequelizeInstance stay as they are.
  2. Measure every migration PR using the CI job durations of all dialects. Locally, a mocha reporter that attributes time to tests, hooks and SQL statements makes the effect visible per file; we could add it under test/ behind an env var (e.g. SEQ_TEST_PROFILE=1) so anyone can find the next file to migrate.
  3. Optionally make setResetMode dialect-aware (suggested in #15886), e.g. setResetMode('destroy', { dialects: [...] }), for suites where only some dialects need a full drop.
  4. Once most slow files are migrated, flip the default to none, with two safety nets:
    • if a test fails, fall back to drop for the rest of that suite, so one failure does not cascade into unrelated tests (the idea from #15886);
    • clear the database when moving to the next test file, even for suites without setResetMode, so files stay independent. setResetMode's after hook already does this for suites that call it.
  5. Leave files that are already cheap alone; they only need to work under the new default.

Risks

  • Tests that silently depend on a clean database (e.g. findAll() expecting exact counts) will fail once tables persist. These are real test bugs, but they surface as churn in the migration PRs.
  • destroy and truncate don't reset identity columns the same way on every dialect. Tests asserting specific IDs need to use the IDs of the created rows.
  • MSSQL and DB2 cannot drop tables that are still referenced by foreign keys from leftover tables. The file-boundary cleanup and drop fallback cover this.
  • SQLite runs on a local file and gains little. It must keep working, but it shouldn't drive the design.

Source: sequelize/sequelize

View original on GitHubView discussion on GitHub