Skip to content
Extraits de code Groupes Projets
Valider 1393a9cd rédigé par mattab's avatar mattab
Parcourir les fichiers

Fixes #6651 Adding better health checks to the tests when downloading/creating files

parent c091edfa
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -36,20 +36,12 @@ class SqlDump extends Fixture
$dumpPath = $this->dumpUrl;
} else {
$dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz';
$bufferSize = 1024 * 1024;
$bytesRead = $this->downloadDumpInPath($dumpPath);
$dump = fopen($this->dumpUrl, 'rb');
$outfile = fopen($dumpPath, 'wb');
$bytesRead = 0;
while (!feof($dump)) {
fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
$bytesRead += $bufferSize;
}
fclose($dump);
fclose($outfile);
if ($bytesRead <= 40 * 1024 * 1024) { // sanity check
throw new Exception("Could not download sql dump!");
// sanity check
if ($bytesRead <= 40 * 1024 * 1024) {
$str = "Could not download sql dump! You can manually download %s into %s";
throw new Exception(sprintf($str, $this->dumpUrl, $dumpPath));
}
}
......@@ -93,4 +85,24 @@ class SqlDump extends Fixture
{
// empty
}
/**
* @param $dumpPath
* @return int
*/
protected function downloadDumpInPath($dumpPath)
{
$bufferSize = 1024 * 1024;
$dump = fopen($this->dumpUrl, 'rb');
$outfile = fopen($dumpPath, 'wb');
$bytesRead = 0;
while (!feof($dump)) {
fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
$bytesRead += $bufferSize;
}
fclose($dump);
fclose($outfile);
return $bytesRead;
}
}
\ No newline at end of file
......@@ -727,6 +727,10 @@ class Fixture extends \PHPUnit_Framework_Assert
$dump = fopen($url, 'rb');
$outfile = fopen($outfileName, 'wb');
if(!$outfile) {
throw new Exception("Failed to create file $outfileName - please check permissions");
}
while (!feof($dump)) {
fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter