From 18bbdf5fb35ee3e8a548b09bea72e33c82733be0 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Thu, 31 Oct 2024 19:43:46 +0100 Subject: [PATCH] [CI] Fix randomly failed tests on Windows v2 (#75) * Try to fix randomly failed tests by removing the dir in tearDown() * Try catch the exception and try again in a second * Rebuild CI * Improve the warning message Co-authored-by: Kevin Bond * Don't need to check if dir exist - it always should be created * Drop the whole dir w/o pre-deleting files one by one * Revert "Drop the whole dir w/o pre-deleting files one by one" This reverts commit a723b10080b880ea1841fdcf9db6836daab5093e. * use filesystem->remove() instead of unlink() * Try to delete the folder in a loop during 5 seconds * Just remove the dir with files * Remove pointless addWarning() in tearDown() and simplify logic * Drop temporary files that were committed --------- Co-authored-by: Kevin Bond --- tests/TailwindBuilderTest.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/TailwindBuilderTest.php b/tests/TailwindBuilderTest.php index 0283616..cb7292e 100644 --- a/tests/TailwindBuilderTest.php +++ b/tests/TailwindBuilderTest.php @@ -11,8 +11,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; use Symfonycasts\TailwindBundle\TailwindBuilder; class TailwindBuilderTest extends TestCase @@ -20,18 +20,27 @@ class TailwindBuilderTest extends TestCase protected function setUp(): void { $fs = new Filesystem(); - if (file_exists(__DIR__.'/fixtures/var/tailwind')) { - $fs->remove(__DIR__.'/fixtures/var/tailwind'); - } $fs->mkdir(__DIR__.'/fixtures/var/tailwind'); } protected function tearDown(): void { - $finder = new Finder(); - $finder->in(__DIR__.'/fixtures/var/tailwind')->files(); - foreach ($finder as $file) { - unlink($file->getRealPath()); + $fs = new Filesystem(); + $i = 0; + // Sometimes "Permission denied" error happens on Windows + // so try to clean up the dir a few times + while (true) { + try { + $fs->remove(__DIR__.'/fixtures/var/tailwind'); + break; + } catch (IOException $e) { + if ($i++ > 5) { + // Still not able to delete it? Throw + throw $e; + } + // Try again in a second + sleep(1); + } } }