-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[AssetMapper] Surround brittle test teardown with try/catch
#57346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6d361f2
to
9d917c4
Compare
If I don't miss anything, this failure reveals an issue in the behaviour of the Filesystem component on Windows (I started debugging this in #54762). I am fine with doing this as a workaround for now, but we somehow need to keep track of the issue nonetheless and try to fix it. |
I'm surprised there's a bug in Filesystem and it only appeared now 😮 My first impression is that it is linked to |
Could it be some race conditions between tests ? As the other failing tests on this PR CI checks are also FileSystem linked to file permissions... and never happened IRL ? Update: could we try the same code as before but remove the parralel runs ? |
It seems that chmod is involved. Here's what I wrote to @xabbuh :
I have no better idea than disabling the related test for Windows, so we're still discussing what's the best way to solve this before ignoring anything 🙂 |
Just discovering Filesystem tests use a markAsSkippedIfChmodIsMissing() method for this very same reason.. protected function markAsSkippedIfChmodIsMissing()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}
} Example in the testRemoveThrowsExceptionOnPermissionDenied method public function testRemoveThrowsExceptionOnPermissionDenied()
{
$this->markAsSkippedIfChmodIsMissing();
$basePath = $this->workspace.\DIRECTORY_SEPARATOR.'dir_permissions';
mkdir($basePath);
$file = $basePath.\DIRECTORY_SEPARATOR.'file';
touch($file);
chmod($basePath, 0400);
try {
$this->filesystem->remove($file);
$this->fail('Filesystem::remove() should throw an exception');
} catch (IOException $e) {
$this->assertStringContainsString('Failed to remove file "'.$file.'"', $e->getMessage());
$this->assertStringContainsString('Permission denied', $e->getMessage());
} finally {
// Make sure we can clean up this file
chmod($basePath, 0777);
}
} |
@alexandre-daubois I opened a PR because I did not see any other way for me to check on Windows. I don't want to appear impolite by opening another one, especially when it's my code at fault here 🫨 |
The remaining one seems to me like it's really a bug in filesystem on windows... Could this be related to this change, with windows handling of "dotfiles" ? // BEFORE
echo \dirname(realpath($file)).'/.'.strrev(strtr(base64_encode(random_bytes(2)), '/=', '-.'));
// ex: /tmp/..AGk
// --> iIgnored by the iterator FilesystemIterator::SKIP_DOTS in order to remove its child before itself
// AFTER
echo \dirname(realpath($file)).'/.'.strrev(strtr(base64_encode(random_bytes(2)), '/=', '-_'));
// ex: /tmp/._IC2
// --> Not ignored or wrong order ?
|
That's totally fine 😄 It seems that only the cleanup part fails, but the rest of the
Would definitely worth a look, I'll give it a deeper look soon 👍 |
This thread seems to confirm it (or at least give some weight) .. as now some folder would be handled before files in it if i read it correctly Alpha order of Windows seems to be:
(image taken from the stackoverflow thread) Seeing the algorithm in the |
Let's try #57574 |
…grekas) This PR was merged into the 5.4 branch. Discussion ---------- [Filesystem] Fix Filesystem::remove() on Windows | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | #57375, #57346 | License | MIT Let's experiment with `@smnandre`'s theory. Commits ------- 2b50dea [Filesystem] Fix Filesystem::remove() on Windows
AppVeyor fails regularly when tearing down
RemotePackageStorageTest
. I think it is acceptable to surround it with atry/catch
, because everything will be erased in AppVeyor once the test suite is ran.