From 2c4bfcec4122d5a1a77c8e3bf91805c15cc14062 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 12:01:39 +0000 Subject: [PATCH] test(driver-sqlite-wasm): run the persistence suites' temp files on /dev/shm, so a flush's fsync stops waiting on the shard's other suites The on-write and flush cases timed out on Test Core shards because each flush's fsync queued behind unrelated suites' disk I/O. Point TMPDIR at a writable /dev/shm in this package's vitest config; the code path, the assertions and the 5 s budget are unchanged. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5oKUikM4XcQpd1HJ6U --- .../driver-sqlite-wasm/vitest.config.ts | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/drivers/driver-sqlite-wasm/vitest.config.ts b/packages/drivers/driver-sqlite-wasm/vitest.config.ts index 092f3349553..08fbf987a6e 100644 --- a/packages/drivers/driver-sqlite-wasm/vitest.config.ts +++ b/packages/drivers/driver-sqlite-wasm/vitest.config.ts @@ -1,4 +1,56 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. -// This package needs nothing beyond the shared preset; see its header. -export { default } from '../../../vitest.preset.mts'; +import { accessSync, constants } from 'node:fs'; +import { defineConfig } from 'vitest/config'; + +// This package re-exported the shared preset until #27076. It now carries one +// key of its own, `test.env.TMPDIR`, so the preset's one setting is restated +// below (a merged or wrapped preset is not what +// scripts/check-console-intercept-disarm.mjs judges in a config's place). +// Every other key stays on vitest's defaults (`globals: false`, +// `environment: 'node'`), exactly as under the bare re-export. +// +// ## Why TMPDIR points at a memory-backed directory +// +// The persistence tests write a real database file under `os.tmpdir()`, and +// every flush ends in `atomicWriteFile`'s `handle.sync()` (fsync before the +// rename; see wasm-connection.ts). An fsync waits for the disk's queue, and on +// a Test Core shard that queue belongs to the other suites sharing the runner. +// Measured (#27076): `should persist data on-write` takes about 30 ms on an +// idle disk and 5,026 ms on schedule run 40654333991 (Test Core 6/8), where it +// timed out; run 39853791549 timed out five on-write and flush cases the same +// way. Locally, with four `dd … conv=fsync` writers on the same disk, those +// cases took 1.4–3.6 s; with TMPDIR on /dev/shm under the same writers, every +// case in the four persistence files stayed under 0.6 s. +// +// So the cases' wall time measured the neighbours' disk, not the driver. On a +// tmpfs the same code still runs, `sync()` included: what each case asserts +// (bytes on disk, atomic rename, the flush chain, the failure report) is +// unchanged; only the wait for unrelated I/O is gone. Budgets, fixtures and +// cases are untouched. +// +// A host without a writable /dev/shm (macOS, Windows) keeps its own temp +// directory: the setting is absent there, not an error. +const MEMORY_BACKED_TMP = '/dev/shm'; + +function writableDir(dir: string): boolean { + try { + accessSync(dir, constants.W_OK); + return true; + } catch { + return false; + } +} + +export default defineConfig({ + test: { + // A late console.* must not redden a green suite (#10374): vitest's worker + // forwards console output over RPC and discards the promise, and a write + // landing after teardown's rpcDone() snapshot is rejected into an unhandled + // error — a fully green run that exits 1. Disarming removes the mechanism. + // Mechanism + measured costs: examples/app-showcase/vitest.config.ts. + // Enforced repo-wide by scripts/check-console-intercept-disarm.mjs. + disableConsoleIntercept: true, + env: writableDir(MEMORY_BACKED_TMP) ? { TMPDIR: MEMORY_BACKED_TMP } : {}, + }, +});