diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8424274..d4f492d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,13 +30,14 @@ jobs: # typecheck uses `bun check`; the published `dist` is emitted by tsc, so build it too. - name: Build run: bun run build + # scripts/test-parallel.ts: files in parallel processes, timing-sensitive files serially. - name: Run tests - run: bun test --timeout 10000 + run: bun run test # The native PostgreSQL suite (POSTGRES_TEST=true) on every supported server major. # test/docker.ts provisions the server itself: it runs DURON_TEST_POSTGRES_IMAGE as the # container duron-postgres-test- on port 5440 and creates one database per test - # with `docker exec` (createdb/psql/dropdb). The runner's Docker daemon is enough, so no + # over SQL from a template database. The runner's Docker daemon is enough, so no # `services:` container is used (docker.ts would refuse one that holds port 5440). native: timeout-minutes: 60 @@ -61,7 +62,7 @@ jobs: run: docker pull "$DURON_TEST_POSTGRES_IMAGE" # Every PostgreSQL test runs only with POSTGRES_TEST; the test job above is PGlite only. - name: Run native tests - run: bun test --timeout 10000 + run: bun run test - name: PostgreSQL container logs if: failure() run: docker logs "duron-postgres-test-${DURON_TEST_POSTGRES_IMAGE//[^a-zA-Z0-9_.-]/-}" 2>&1 | tail -200 diff --git a/.oxlintrc.json b/.oxlintrc.json index 5d37302..c117200 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -11,7 +11,12 @@ "suspicious": "warn" }, "rules": { - "import/no-unassigned-import": ["error", { "allow": ["./app.css", "**/*.css"] }], + "import/no-unassigned-import": [ + "error", + { + "allow": ["./app.css", "**/*.css"] + } + ], "no-underscore-dangle": "off" }, "overrides": [ @@ -20,6 +25,12 @@ "rules": { "no-shadow": "off" } + }, + { + "files": ["packages/duron/test/*.test.ts"], + "rules": { + "unicorn/consistent-function-scoping": "off" + } } ], "ignorePatterns": ["dist", "build", "node_modules", ".wrangler", "**/*.gen.ts", "**/env.d.ts"] diff --git a/AGENTS.md b/AGENTS.md index e0be5f4..b8fc230 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,7 +39,7 @@ bun run lint # oxlint check bun run lint:fix # oxlint fix bun run fmt:check # oxfmt check bun run fmt # oxfmt fix -bun test --timeout 10000 # runs packages/duron tests (same as `bun run test`) +bun run test # packages/duron tests in parallel processes (scripts/test-parallel.ts) # Build bun run build # all packages @@ -61,9 +61,19 @@ bun run build:docs # docs only - Framework: `bun:test` - Tests live in `packages/duron/test/*.test.ts` - Run single file: `bun test --timeout 10000 specific.test.ts` -- Default per-test timeout: pass `--timeout 10000` (the `test` script and CI do). Bun ignores a `timeout` key in `bunfig.toml` (oven-sh/bun#7789), so a plain `bun test` uses 5000 ms. -- Core tests run with `bun test --timeout 10000` (no `--concurrent`: many suites share native resources and time-sensitive lifecycle budgets, and fail under cross-file concurrency) -- A plain `bun test --timeout 10000` runs PGlite only and needs no Docker. PostgreSQL tests run only with `POSTGRES_TEST=true`; every file that uses PostgreSQL gates it on that variable. +- Default per-test timeout: pass `--timeout 10000` (the runner and CI do). Bun ignores a `timeout` key in `bunfig.toml` (oven-sh/bun#7789), so a plain `bun test` uses 5000 ms. +- Full suite: `bun run test` (root or `packages/duron`) runs `packages/duron/scripts/test-parallel.ts`. CI uses it too. + - Each test file runs in its own `bun test --timeout 10000 ` process. Files without wall-clock budgets run in a pool of `--jobs N` processes (default: half the CPU cores; `DURON_TEST_JOBS` overrides). + - Files with wall-clock budgets (the `SERIAL` list in the script: `lifecycle*`, `prune-*`, `stop*`, `shutdown-*`, `wait-native*`, `wait-timing`, `discovery-throughput`, `claim-isolation`, `claim.test`, `cross-mechanism`, `step-abort-settlement`, `local-cancellation.test`, `worker-discovery`) run after the pool, one at a time, with no other test process. Add a file there when it asserts elapsed time or observes timers/cadences under a bound, and put a timing-sensitive test only in a file of that list. +- Test files are grouped by feature (for example `lifecycle.test.ts`, `prune-lock.test.ts`, `prune-scheduler.test.ts`, `wait.test.ts`, `wait-timing.test.ts`). Each former file is one `{ ... }` block with its own helpers, under a `// ===` banner with its old name; the imports are shared at the top. Keep a new group's helpers inside its block (the lint override for `packages/duron/test/*.test.ts` turns off `unicorn/consistent-function-scoping` for this reason). + - Output: one line per finished file (pass/skip/fail counts, time); then the complete output of each failed file, a per-file count table and the totals. Exit status 1 when a file fails (non-zero `bun test` exit, a failed test, no summary, or longer than the file timeout: 300000 ms, `--file-timeout` or `DURON_TEST_FILE_TIMEOUT`; a timed-out file is killed and reported by name, and the run continues). Every file's log is kept in `DURON_TEST_LOG_DIR` (default: a new temporary directory; the path is printed). + - Filters: `bun run test -- wait-` (in `packages/duron`) runs the files whose path contains a filter. +- `bun test --timeout 10000` (root, or `bun run test:serial` in `packages/duron`) still runs every file in one process, one file after another. It is slower; use it for one file or to compare. +- PGlite tests need no Docker. PostgreSQL tests run only with `POSTGRES_TEST=true`; every file that uses PostgreSQL gates it on that variable. +- Test databases (`test/adapters.ts`, `test/docker.ts`): + - `pgliteFactory` / `postgresFactory` give a database with all migrations already applied; `migrateOnStart` only checks them. With `fresh: true` or `migrateOnStart: false` the database is empty (as a new one). Use `fresh: true` in a test that observes the migrations themselves. + - PGlite: each process dumps one migrated and one empty engine once (`dumpDataDir`); every factory engine starts from a dump (`loadDataDir`), which skips `initdb` (about 450 ms of the 500 ms of a new engine). + - PostgreSQL: each test database is `CREATE DATABASE "" TEMPLATE "