Skip to content

Commit 18bbdf5

Browse files
bocharsky-bwkbond
andauthored
[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 <[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]>
1 parent 551f5cd commit 18bbdf5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tests/TailwindBuilderTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,36 @@
1111

1212
use PHPUnit\Framework\TestCase;
1313
use Symfony\Component\Cache\Adapter\ArrayAdapter;
14+
use Symfony\Component\Filesystem\Exception\IOException;
1415
use Symfony\Component\Filesystem\Filesystem;
15-
use Symfony\Component\Finder\Finder;
1616
use Symfonycasts\TailwindBundle\TailwindBuilder;
1717

1818
class TailwindBuilderTest extends TestCase
1919
{
2020
protected function setUp(): void
2121
{
2222
$fs = new Filesystem();
23-
if (file_exists(__DIR__.'/fixtures/var/tailwind')) {
24-
$fs->remove(__DIR__.'/fixtures/var/tailwind');
25-
}
2623
$fs->mkdir(__DIR__.'/fixtures/var/tailwind');
2724
}
2825

2926
protected function tearDown(): void
3027
{
31-
$finder = new Finder();
32-
$finder->in(__DIR__.'/fixtures/var/tailwind')->files();
33-
foreach ($finder as $file) {
34-
unlink($file->getRealPath());
28+
$fs = new Filesystem();
29+
$i = 0;
30+
// Sometimes "Permission denied" error happens on Windows
31+
// so try to clean up the dir a few times
32+
while (true) {
33+
try {
34+
$fs->remove(__DIR__.'/fixtures/var/tailwind');
35+
break;
36+
} catch (IOException $e) {
37+
if ($i++ > 5) {
38+
// Still not able to delete it? Throw
39+
throw $e;
40+
}
41+
// Try again in a second
42+
sleep(1);
43+
}
3544
}
3645
}
3746

0 commit comments

Comments
 (0)