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

104 lines
4.2 KiB
PHP

<?php
$root = dirname(__DIR__, 2);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if (!is_string($contents)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$xcat = $read('web/app/Command/XCat.php');
$command = $read('web/app/Command/CloudStoragePublicationWorker.php');
$outbox = $read(
'web/app/Services/Cloud/CloudStoragePublicationOutboxService.php'
);
$replicaWorker = $read(
'web/app/Services/Cloud/CloudStorageReplicaWorkerService.php'
);
$heartbeat = $read('web/app/Services/Cloud/CloudRuntimeHeartbeat.php');
$runtime = $read('web/app/Services/Cloud/CloudRuntimeHealthService.php');
$unit = $read(
'deploy/virt-cloud-storage-publication-worker.service'
);
$deployment = $read('docs/DEPLOYMENT.md');
$repairPosition = strpos(
$replicaWorker,
'CloudStorageReplicaRepairService'
);
$claimPosition = strpos($replicaWorker, 'claimReplicaWork');
$assert(str_contains($xcat, "'cloudStoragePublicationWorker'")
&& str_contains($xcat, 'CloudStoragePublicationWorker::run')
&& str_contains(
$xcat,
'php xcat cloudStoragePublicationWorker [--once]'
), 'Publication worker is not reachable through xcat and its help.');
$assert(str_contains($command, 'CloudStoragePublicationOutboxService')
&& !str_contains($command, 'CloudStorageReplicaWorkerService')
&& str_contains($command, "in_array('--once'")
&& str_contains($command, "'storage_publication'")
&& str_contains($command, "busy('storage_publication_tick')")
&& str_contains($command, "error('storage_publication_failed')")
&& str_contains($command, '$unresolved = true;')
&& str_contains($command, 'elseif (!$unresolved)')
&& str_contains($command, 'usleep(1000000)'),
'Publication worker lost its isolated loop, heartbeat, warning memory, '
. 'or bounded idle polling.');
$assert(str_contains($outbox, "where('state', 'ready_to_finalize')")
&& str_contains($outbox, "->whereNull('backup_id')")
&& str_contains($outbox, 'CloudTemplateStoragePublicationConsumer')
&& str_contains($outbox, 'finalizeReadyOnly'),
'Publication worker can consume backups or lost its template/rescue '
. 'owner boundary.');
$assert(!str_contains($replicaWorker, 'CloudStoragePublicationOutboxService')
&& !str_contains($replicaWorker, 'storage_publication')
&& is_int($repairPosition) && is_int($claimPosition)
&& $repairPosition < $claimPosition,
'Replica worker retained publication work or lost repair-before-copy '
. 'ordering.');
$assert(str_contains($heartbeat, "'storage_publication' => [")
&& str_contains($heartbeat, "'storage_publication_tick'")
&& str_contains($heartbeat, "'storage_publication_failed'")
&& str_contains(
$runtime,
"'storage_publication' => '对象存储业务发布'"
), 'Publication runtime heartbeat is not independently observable.');
$assert(str_contains(
$unit,
'ExecStart=/usr/bin/php /home/virt-cloud/web/xcat '
. 'cloudStoragePublicationWorker'
)
&& str_contains($unit, 'NoNewPrivileges=true')
&& str_contains($unit, 'PrivateTmp=true')
&& str_contains($unit, 'ProtectSystem=strict')
&& str_contains($unit, 'LimitCORE=0')
&& str_contains($unit, 'ReadWritePaths=-/home/virt-cloud/web/storage')
&& !str_contains($unit, '%i'),
'Publication systemd unit lost single-instance execution or hardening.');
$assert(str_contains(
$deployment,
'cp /home/virt-cloud/deploy/'
. 'virt-cloud-storage-publication-worker.service'
)
&& str_contains(
$deployment,
'virt-cloud-storage-publication-worker.service'
)
&& str_contains(
$deployment,
'-u virt-cloud-storage-publication-worker.service'
)
&& str_contains($deployment, 'ready_to_finalize')
&& str_contains($deployment, '普通云备份仍由原同步流程最终化'),
'Publication worker deployment, journal, or missing-service impact is '
. 'not documented.');
echo "Storage publication worker contract tests passed.\n";