[Tests] Isolate ApplicationFileProcessorTest cache dir to survive parallel chunk clears - #8361
Closed
TomasVotruba wants to merge 1 commit into
Closed
[Tests] Isolate ApplicationFileProcessorTest cache dir to survive parallel chunk clears#8361TomasVotruba wants to merge 1 commit into
TomasVotruba wants to merge 1 commit into
Conversation
…allel chunk clears
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.
ApplicationFileProcessorTestasserts real cache persistence (save then load) against the shared cache directorysys_get_temp_dir() . '/rector_cached_files'. Underfastunit -tia, test chunks run as parallel processes that all share that one directory, andFileCacheStorage::clear()deletes the whole directory:So a sibling chunk can wipe this test's cache entry between the save and the load, making
hasFileChanged()find nothing and returntrue("be defensive and assume it's changed"). The three cache-scope tests then fail withFailed asserting that true is false.— non-deterministically, depending on chunk timing.Fix
Bind a dedicated cache directory for this test only, so no other chunk's
clear()can touch it:protected function setUp(): void { parent::setUp(); + // isolate the cache directory to this test - the default directory is shared across all + // parallel test chunks, and FileCacheStorage::clear() deletes the whole directory, so a + // sibling chunk can wipe this test's cache between save and load and flip the assertions + $rectorConfig = self::getContainer(); + SimpleParameterProvider::setParameter( + Option::CACHE_DIR, + sys_get_temp_dir() . '/rector_test_application_file_processor' + ); + $rectorConfig->singleton( + Cache::class, + static fn (Container $container): Cache => $container->make(CacheFactory::class)->create() + ); + $this->applicationFileProcessor = $this->make(ApplicationFileProcessor::class); $this->changedFilesDetector = $this->make(ChangedFilesDetector::class); }The
Cachesingleton is rebound so it is rebuilt from the isolated directory (it is otherwise created once per process from the default directory). Test-only change.