test: isolate on-disk storage dirs of parallel test files - #683
Open
B4nan wants to merge 1 commit into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The unit test suite was flaky when run as a whole: every few full runs, a random test (most often in
charging.test.tsoractor.test.ts) failed withI/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
Configurationdefaults to the same cwd-relative./storagedir.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_DIRat 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
./storagedir, and the temp dirs get cleaned up after each file.