You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudPortableRestoreAutomat...

68 lines
2.2 KiB
PHTML

<?php
declare(strict_types=1);
$root = dirname(__DIR__);
$source = file_get_contents(
$root . '/app/Services/Cloud/CloudAutomaticOperationRecoveryService.php'
);
if (!is_string($source)) {
throw new RuntimeException('Unable to read automatic recovery service.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$mode = "if (\$claimed['mode'] === 'portable_restore_finalizer')";
$retry = 'CloudPortableRestoreFinalizer::retryPendingFinalization(';
$assert(str_contains($source, $mode)
&& str_contains($source, $retry),
'Portable restore PHP-only finalization is not dispatched.');
$queryStart = strpos($source,
"->where('kind', 'backup_restore')");
$queryEnd = $queryStart === false ? false : strpos(
$source,
'$mode = \'portable_restore_finalizer\';',
$queryStart
);
$assert($queryStart !== false && $queryEnd !== false,
'Portable restore finalization claim is missing.');
$query = substr($source, $queryStart, $queryEnd - $queryStart);
foreach ([
"'bra.state',\n 'finalization_pending'",
"'bra.effect_resolution'",
"['applied', 'not_applied']",
"->where('bra.active_attempt', 1)",
"'recovery_prepare_pending'",
'self::receivedEventExists($events)',
] as $needle) {
$assert(str_contains($query, $needle),
'Portable restore finalization claim omitted: ' . $needle);
}
$policy = strpos(
$source,
'CloudOperationRecoveryPolicy::allowsSystemResolution('
);
$prepareApplied = strpos(
$source,
'CloudOperationRecoveryService::prepareApplied('
);
$prepareNotApplied = strpos(
$source,
'CloudOperationRecoveryService::prepareNotApplied('
);
$assert($policy !== false && $prepareApplied !== false
&& $prepareNotApplied !== false
&& $policy < $prepareApplied && $policy < $prepareNotApplied,
'System fence policy is not enforced before PHP ledger preparation.');
$assert(str_contains(
substr($source, $policy - 160, 500),
'$fenceResolutionRequired'
), 'The early system-resolution policy is not scoped to active fences.');
echo "Cloud portable restore automatic recovery contract passed.\n";