Backup state stays valid JSON with a name that is not UTF-8; Bin reads on from an id, not a position
This commit is contained in:
@@ -58,16 +58,30 @@ class CatalogTest extends TestCase {
|
||||
$again = $this->open();
|
||||
$seen = [];
|
||||
// A deadline already past: one entry per request, as on a slow location
|
||||
$after = '';
|
||||
for ($request = 0; count($seen) < 3 && $request < 5; $request++) {
|
||||
$page = $again->trashPage(count($seen), 0.0);
|
||||
$page = $again->trashPage($after, 0.0);
|
||||
$this->assertSame(3, $page['total']);
|
||||
$this->assertCount(1, $page['items']);
|
||||
$seen += $page['items'];
|
||||
$after = (string)array_key_last($page['items']);
|
||||
}
|
||||
$this->assertSame(array_keys($again->trash()), array_intersect(array_keys($again->trash()), array_keys($seen)));
|
||||
$this->assertCount(3, $seen);
|
||||
$this->assertSame(['total' => 3, 'items' => []], $again->trashPage(3, 0.0));
|
||||
$this->assertCount(3, $again->trashPage(0, microtime(true) + 60)['items']);
|
||||
$this->assertEqualsCanonicalizing(array_keys($again->trash()), array_keys($seen));
|
||||
$this->assertSame(['total' => 3, 'items' => []], $again->trashPage($after, 0.0));
|
||||
$this->assertCount(3, $again->trashPage('', microtime(true) + 60)['items']);
|
||||
}
|
||||
|
||||
public function testAnEntryThatLeavesTheTrashBetweenPartsMakesNoneComeTwiceOrBeMissed(): void {
|
||||
$repo = Repository::initWithKey($this->backend, $this->keys, $this->keys->wrap('pw'), $this->anchor);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$repo->forget($repo->backupDirectory($this->src)['snapshot']);
|
||||
}
|
||||
$reader = $this->open();
|
||||
$ids = array_keys($reader->trashPage('', microtime(true) + 60)['items']);
|
||||
$first = $reader->trashPage('', 0.0)['items'];
|
||||
$this->assertSame([$ids[0]], array_keys($first));
|
||||
$this->open()->untrash($ids[0]); // another administrator, between two parts
|
||||
$this->assertSame([$ids[1], $ids[2]], array_keys($this->open()->trashPage($ids[0], microtime(true) + 60)['items']));
|
||||
}
|
||||
|
||||
public function testRollbackIsDetected(): void {
|
||||
|
||||
@@ -78,10 +78,11 @@ class EmptyDirsTest extends TestCase {
|
||||
file_put_contents("$this->src/data/alice/files/\xff.txt", 'x');
|
||||
$state = BackupRun::start(['data' => "$this->src/data"]);
|
||||
for ($i = 0; $i < 50 && $state['phase'] !== 'commit'; $i++) {
|
||||
$state = BackupRun::step($this->repo(), $state, microtime(true) + 30);
|
||||
// A step per entry, state through JSON: as separate processes would
|
||||
$state = json_decode(json_encode(BackupRun::step($this->repo(), $state, 0.0), JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$this->assertSame('commit', $state['phase']);
|
||||
$this->assertSame(4, $state['stats']['unreadable']);
|
||||
$this->assertSame(4, $state['stats']['unreadable'], 'each reported once, over several steps');
|
||||
$this->repo()->recordSnapshot($state['snapshot']);
|
||||
|
||||
$this->assertSame(['data/alice/files/Hollow/Nested', 'data/skipped/inner'], array_column($this->repo()->emptyDirs($state['snapshot']), 0));
|
||||
|
||||
@@ -99,7 +99,7 @@ done
|
||||
occ backup:list ci | grep " page " >/dev/null || fail "the snapshot of the ticked backup is not listed"
|
||||
ok "without system cron: warning in backup:status and the API, backup finished by $i ticks of the open page"
|
||||
# The Bin reads in parts, as the page does (what is in the parts: CatalogTest)
|
||||
api "$API/targets/$TID/trash?offset=0" | php -r '$p = json_decode(stream_get_contents(STDIN), true); exit(is_int($p["total"] ?? null) && is_array($p["items"] ?? null) && count($p["items"]) <= $p["total"] ? 0 : 1);' || fail "the Bin API does not give a total and items"
|
||||
api "$API/targets/$TID/trash" | php -r '$p = json_decode(stream_get_contents(STDIN), true); exit(is_int($p["total"] ?? null) && is_array($p["items"] ?? null) && count($p["items"]) <= $p["total"] ? 0 : 1);' || fail "the Bin API does not give a total and items"
|
||||
ok "the Bin API reads in parts, with a total"
|
||||
occ background:cron >/dev/null
|
||||
$X php -f /var/www/html/cron.php >/dev/null 2>&1 || true
|
||||
|
||||
Reference in New Issue
Block a user