51a4a67bc4
Reserved in Nextcloud's job list, so no app is turned off and a job that is running goes on. At most 6 hours in a row, then they get an hour; Nextcloud ends a reservation by itself after 12 hours, should the end of a pause never come. On by default, with a setting to turn it off.
36 lines
1.4 KiB
PHP
36 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\NgBackup\Tests\Unit\Service;
|
|
|
|
use OCA\NgBackup\Service\HeavyJobPause as P;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class HeavyJobPauseTest extends TestCase {
|
|
private const NOW = 1000000;
|
|
|
|
public function testDuringABackupTheyArePaused(): void {
|
|
$this->assertSame(P::PAUSE, P::decide(true, true, 0, 0, self::NOW));
|
|
$this->assertSame(P::PAUSE, P::decide(true, true, self::NOW - 60, 0, self::NOW), 'jobs added since then too');
|
|
}
|
|
|
|
public function testWithoutABackupNothingHappensOrThePauseEnds(): void {
|
|
$this->assertSame(P::NOTHING, P::decide(true, false, 0, 0, self::NOW));
|
|
$this->assertSame(P::RELEASE, P::decide(true, false, self::NOW - 60, 0, self::NOW));
|
|
}
|
|
|
|
public function testTurningItOffEndsThePause(): void {
|
|
$this->assertSame(P::NOTHING, P::decide(false, true, 0, 0, self::NOW));
|
|
$this->assertSame(P::RELEASE, P::decide(false, true, self::NOW - 60, 0, self::NOW));
|
|
}
|
|
|
|
public function testAfterSixHoursTheyGetTheirTurnAndThenPauseAgain(): void {
|
|
$this->assertSame(P::PAUSE, P::decide(true, true, self::NOW - P::MAX_SECONDS + 1, 0, self::NOW));
|
|
$this->assertSame(P::REST, P::decide(true, true, self::NOW - P::MAX_SECONDS, 0, self::NOW));
|
|
$rest = self::NOW + P::REST_SECONDS;
|
|
$this->assertSame(P::NOTHING, P::decide(true, true, 0, $rest, $rest - 1));
|
|
$this->assertSame(P::PAUSE, P::decide(true, true, 0, $rest, $rest));
|
|
}
|
|
}
|