From b751156e1cdc798fc8b0ec06af7cae8ac3e8a22a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 2 Jun 2021 10:00:01 +0200 Subject: [PATCH] Prevent cache gc from happening during test suite runs, and add output so it is clear why it is blocking for a bit --- phpunit.xml.dist | 1 + src/Composer/Cache.php | 17 +++++++++++++++-- src/Composer/Downloader/FileDownloader.php | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 75c2f3c74..dd72dd5ee 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,7 @@ > + diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php index 9590693ff..a3aaebf57 100644 --- a/src/Composer/Cache.php +++ b/src/Composer/Cache.php @@ -24,7 +24,7 @@ use Symfony\Component\Finder\Finder; */ class Cache { - private static $cacheCollected = false; + private static $cacheCollected = null; private $io; private $root; private $enabled = true; @@ -191,7 +191,20 @@ class Cache public function gcIsNecessary() { - return (!self::$cacheCollected && !mt_rand(0, 50)); + if (self::$cacheCollected) { + return false; + } + + self::$cacheCollected = true; + if (getenv('COMPOSER_TEST_SUITE')) { + return false; + } + + if (PHP_VERSION_ID > 70000) { + return !random_int(0, 50); + } + + return !mt_rand(0, 50); } public function remove($file) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 793e74d2b..63cba2e3c 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -84,6 +84,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface $this->filesystem = $filesystem ?: new Filesystem($this->process); if ($this->cache && $this->cache->gcIsNecessary()) { + $this->io->writeError('Running cache garbage collection', true, IOInterface::VERY_VERBOSE); $this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize')); } }