Skip to content

test: isolate on-disk storage dirs of parallel test files - #683

Open
B4nan wants to merge 1 commit into
v4from
test/isolate-unit-test-storage-dirs
Open

test: isolate on-disk storage dirs of parallel test files#683
B4nan wants to merge 1 commit into
v4from
test/isolate-unit-test-storage-dirs

Conversation

@B4nan

@B4nan B4nan commented Aug 7, 2026

Copy link
Copy Markdown
Member

The unit test suite was flaky when run as a whole: every few full runs, a random test (most often in charging.test.ts or actor.test.ts) failed with I/O error: No such file or directory (os error 2).

The cause is a race on shared on-disk storage. Vitest runs test files in parallel worker processes, and every Configuration defaults to the same cwd-relative ./storage dir. Actor.init() in one worker purges the default storages from disk while another worker's test is reading or writing the same paths through the fs storage backend, which then throws ENOENT. Any test file that touches real disk storage can be either the culprit or the victim, which is why the failing test varies between runs.

The fix adds a vitest setup file that points CRAWLEE_STORAGE_DIR at a fresh temp dir before each test file runs and removes it again afterwards, so parallel workers never share storage paths. The test assertions are unchanged.

I verified this by running the full suite in a loop: without the fix it failed within 6 attempts in both tries, with the fix all 20 runs passed. Unit tests also no longer create the repo-root ./storage dir, and the temp dirs get cleaned up after each file.

Vitest runs test files in parallel worker processes, but every Configuration
defaulted to the same cwd-relative ./storage dir, so one file's purge-on-init
raced against another file's reads/writes and intermittently failed random
tests with "I/O error: No such file or directory (os error 2)" from the fs
storage backend. A vitest setup file now points CRAWLEE_STORAGE_DIR at a
per-test-file temp dir (removed again after the file finishes).
@B4nan B4nan added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants