1
0
Fork 0

Prevent cache gc from happening during test suite runs, and add output so it is clear why it is blocking for a bit

pull/9928/head
Jordi Boggiano 2021-06-02 10:00:01 +02:00
parent a23f8a3d6c
commit b751156e1c
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 17 additions and 2 deletions

View File

@ -16,6 +16,7 @@
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="COMPOSER_TEST_SUITE" value="1"/>
</php>
<testsuites>
<testsuite name="Composer Test Suite">

View File

@ -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)

View File

@ -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'));
}
}