36a30732ad
- The admin page and backup:status warn when background jobs do not run on a
system cron, or the cron stopped, with a link to how to set one up.
- Without a working system cron, the open admin page moves a running backup
forward through /api/tick, a short step per poll.
- The database phase shows the tables dumped ("db: 47/183 tables"); a backup
that has not moved for 15 minutes says it is waiting for background jobs.
- The trash of restore points is on a tab of its own, Bin.
- New screenshots; changelog and plan for 1.0.2.
49 lines
2.2 KiB
PHP
49 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\NgBackup\Tests\Unit\Job;
|
|
|
|
use OCA\NgBackup\Job\BackupRun;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BackupProgressTest extends TestCase {
|
|
public function testCountsFinishedFilesAndTheFileBeingRead(): void {
|
|
$state = ['phase' => 'files', 'estimate' => ['bytes' => 1000, 'approximate' => false],
|
|
'stats' => ['bytes' => 500], 'cur' => ['offset' => 180]];
|
|
$this->assertSame(['fraction' => 0.68, 'approximate' => false], BackupRun::progress($state));
|
|
}
|
|
|
|
public function testStaysBelowHundredPercentWhenTheEstimateIsTooLow(): void {
|
|
$state = ['phase' => 'files', 'estimate' => ['bytes' => 1000, 'approximate' => true], 'stats' => ['bytes' => 5000], 'cur' => null];
|
|
$this->assertSame(['fraction' => 0.99, 'approximate' => true], BackupRun::progress($state));
|
|
}
|
|
|
|
public function testNoProgressWithoutEstimateOrOutsideTheFilesPhase(): void {
|
|
$this->assertNull(BackupRun::progress(['phase' => 'files', 'stats' => ['bytes' => 1]]));
|
|
$this->assertNull(BackupRun::progress(['phase' => 'files', 'estimate' => ['bytes' => 0, 'approximate' => true], 'stats' => ['bytes' => 1]]));
|
|
$this->assertNull(BackupRun::progress(['phase' => 'commit', 'estimate' => ['bytes' => 10, 'approximate' => false], 'stats' => ['bytes' => 1]]));
|
|
}
|
|
|
|
private static function runIn(string $phase, array $state, string $status = \OCA\NgBackup\Db\Run::RUNNING): \OCA\NgBackup\Db\Run {
|
|
$run = new \OCA\NgBackup\Db\Run();
|
|
$run->setStatus($status);
|
|
$run->setPhase($phase);
|
|
$run->setState(json_encode($state, JSON_THROW_ON_ERROR));
|
|
return $run;
|
|
}
|
|
|
|
public function testDatabasePhaseCountsTheTablesDumped(): void {
|
|
$run = self::runIn('db', ['dump' => ['tables' => array_fill(0, 183, 'oc_t'), 'i' => 47]]);
|
|
$this->assertSame(['fraction' => 47 / 183, 'approximate' => false, 'tables' => 47, 'totalTables' => 183], BackupRun::progressOf($run));
|
|
}
|
|
|
|
public function testDatabasePhaseHasNoFigureBeforeItsFirstStep(): void {
|
|
$this->assertNull(BackupRun::progressOf(self::runIn('db', ['files' => []])));
|
|
}
|
|
|
|
public function testNoProgressForAFinishedRun(): void {
|
|
$this->assertNull(BackupRun::progressOf(self::runIn('db', ['dump' => ['tables' => ['oc_a'], 'i' => 0]], \OCA\NgBackup\Db\Run::DONE)));
|
|
}
|
|
}
|