From 4a75e6bb57116bdc6a24571a7ef849c478b1d5f5 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sun, 16 Aug 2026 09:35:37 +0000 Subject: [PATCH] test(moshpit): build the schema before the pins suite, not inside its first test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The master run for #110 failed on one test — "a published pin comes back for every name under the TLD" — timing out at 5s after 6365ms, while the same file passes locally in 172ms. Nothing in that test is slow. Schema creation is lazy, and this suite was the only db suite that never called ensureSchema() at module scope, so the whole of initDb() — dozens of CREATE TABLE/INDEX statements, against a real file on disk rather than the :memory: the sibling suites use — was billed to whichever test touched the database first. That is the first pin test, and it ran inside a 5s timeout it was never really spending on its own work. Warming at module scope moves that cost outside any test's timeout, which is what project-webhook-management, project-inbound-webhook-management, and waitlist-sort-db already do. Measured on a warm machine the test's own time drops 20.6ms -> 4.4ms; on a cold runner that same difference was the 6 seconds. Co-Authored-By: Claude Opus 5 (1M context) --- tests/moshpit-pins.test.mjs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/moshpit-pins.test.mjs b/tests/moshpit-pins.test.mjs index c7dfb55..66198bd 100644 --- a/tests/moshpit-pins.test.mjs +++ b/tests/moshpit-pins.test.mjs @@ -18,6 +18,17 @@ process.env.TURSO_DATABASE_URL = `file:${join(dir, "test.db")}`; const { PIN_KINDS, addPin, isPin, listPins, normalizePinKind, pinsForName, registerTld, removePin, setAlias, } = await import("../lib/moshpit.ts"); +const { ensureSchema } = await import("../lib/db.ts"); + +// Build the schema here rather than leaving it to whichever test touches the +// database first. Schema creation is lazy, so without this the whole of +// initDb() — dozens of CREATE TABLE/INDEX statements against a real file on +// disk — is billed to the first test that calls into the database, inside that +// test's 5s timeout. On a warm machine that is milliseconds and invisible; on a +// cold CI runner it crossed the limit, which is why one pin test failed on CI +// while the file passed locally in 172ms. The sibling db suites +// (project-webhook-management, waitlist-sort-db, …) already warm up this way. +await ensureSchema(); /** A pin is SHA-256 over an SPKI; any 32 bytes stand in for one here. */ const somePin = () => createHash("sha256").update(randomBytes(32)).digest("base64");