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/CloudTrafficPoolLifecycleSc...

63 lines
2.9 KiB
PHP

<?php
$lifecycle = file_get_contents(dirname(__DIR__)
. '/app/Services/Cloud/CloudLifecycleService.php');
$accounting = file_get_contents(dirname(__DIR__)
. '/app/Services/Cloud/CloudTrafficPoolAccounting.php');
if (!is_string($lifecycle) || !is_string($accounting)) {
throw new RuntimeException('Unable to read traffic-pool lifecycle sources.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$sync = strpos($lifecycle, 'CloudTrafficService::sync($batchSize)');
$settle = strpos($lifecycle,
'CloudTrafficPoolAccounting::settlePendingUsage(');
$due = strpos($lifecycle, 'CloudTrafficPoolAccounting::reconcileDue(');
$compact = strpos($lifecycle, 'CloudTrafficSettlementRetention::compact(');
$checkpointCompact = strpos(
$lifecycle, 'CloudTrafficCheckpointRetention::prune('
);
$runtime = strpos($lifecycle,
'(new CloudInstanceRuntimeSyncService())->sync($batchSize)');
$instanceReconcile = strpos($lifecycle,
"\$this->heartbeat?->busy('instance_reconcile')");
$assert($sync !== false && $settle !== false && $due !== false
&& $compact !== false && $checkpointCompact !== false
&& $runtime !== false && $instanceReconcile !== false
&& $sync < $settle && $settle < $due && $due < $compact
&& $compact < $checkpointCompact && $checkpointCompact < $runtime
&& $runtime < $instanceReconcile,
'Lifecycle must sync counters, settle usage, reconcile due periods, '
. 'compact verified history, then continue with runtime and '
. 'per-instance reconciliation.');
$assert(str_contains($lifecycle, 'trafficUsageScanCursor')
&& str_contains($lifecycle, 'trafficPeriodScanCursor')
&& substr_count($lifecycle, "['next_cursor']") >= 2,
'Bounded accounting scans no longer advance past a persistent bad row.');
$privateReconcile = strpos($lifecycle, 'private function reconcile(');
$assert($privateReconcile !== false
&& strpos(substr($lifecycle, $privateReconcile),
'CloudTrafficPoolAccounting::') === false,
'Pool accounting was nested inside the instance-first lifecycle transaction.');
$stage = substr($lifecycle, $settle, $runtime - $settle);
$assert(!str_contains($stage, 'network_status')
&& !str_contains($stage, 'CloudJobService')
&& !str_contains($stage, 'CloudAgentClient')
&& str_contains($stage,
"observeFailure('traffic_pool_accounting_failed')"),
'Shadow accounting changed network policy or lost fail-open observations.');
$assert(!str_contains($accounting, 'CloudAgentClient')
&& !str_contains($accounting, 'network_status')
&& !str_contains($accounting, "'kind' => 'network_suspend'")
&& !str_contains($accounting, "'kind' => 'network_resume'"),
'The shadow accounting module acquired an Agent/network side effect.');
echo "Cloud traffic-pool lifecycle scheduler contract passed.\n";