Skip to content

Commit

Permalink
Make waiting for zipfile's content more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
pabzm committed Jul 5, 2024
1 parent e79ac49 commit 49a6811
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions plugins/zipdownload/tests/Browser/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,28 @@ private function getFilesFromZip($browser, $filename)
$filename = $browser->getDownloadedFilePath($filename);

// Give the browser a chance to finish download
if (!file_exists($filename)) {
sleep(2);
$attempts = 0;
while (!file_exists($filename)) {
if ($attempts > 9) {
throw new \Exception("File not found even after waiting period: {$filename}");
}
sleep(1);
$attempts++;
}
// Wait until the file size doesn't change anymore to be sure to have
// the full file. Under some circumstances the file apparently was used
// before its content was fully written (and sync'ed across the FS
// mounts).
$attempts = 0;
do {
if ($attempts > 9) {
throw new \Exception("File size continues to change, something is wrong! File: {$filename}");
}
$filesize1 = stat($filename)['size'];
sleep(1);
$filesize2 = stat($filename)['size'];
$attempts++;
} while ($filesize1 !== $filesize2);

$zip = new \ZipArchive();
$files = [];
Expand Down

0 comments on commit 49a6811

Please sign in to comment.