a01aa16ccd
A run only showed "running (files)", which says nothing during a backup of a terabyte. The files phase now records an expected size on its first step: the previous snapshot's size, or for a first backup the users' files, versions and trash from Nextcloud's file cache (approximate, shown with a ~). The web interface and occ backup:status show the share of it done so far, including a large file that is still being read; it stays below 100% until the run finishes.
28 lines
1.3 KiB
PHP
28 lines
1.3 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]]));
|
|
}
|
|
}
|