Skip to content

Commit

Permalink
[CI] Fix randomly failed tests on Windows v2 (#75)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 a723b10.

* 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 <[email protected]>
  • Loading branch information
bocharsky-bw and kbond authored Oct 31, 2024
1 parent 551f5cd commit 18bbdf5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/TailwindBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@

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
{
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);
}
}
}

Expand Down

0 comments on commit 18bbdf5

Please sign in to comment.