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.
82 lines
3.2 KiB
PHP
82 lines
3.2 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudAgentReadiness;
|
|
|
|
$assert = static function ($ok, string $message): void {
|
|
if (!$ok) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$now = 10.0;
|
|
$attempts = 0;
|
|
$sleeps = [];
|
|
$ready = CloudAgentReadiness::wait(
|
|
static function () use (&$attempts): bool {
|
|
$attempts++;
|
|
return $attempts === 3;
|
|
},
|
|
3.0,
|
|
static function () use (&$now): float {
|
|
return $now;
|
|
},
|
|
static function (int $microseconds) use (&$now, &$sleeps): void {
|
|
$sleeps[] = $microseconds;
|
|
$now += $microseconds / 1000000;
|
|
},
|
|
);
|
|
$assert($ready && $attempts === 3 && $sleeps === [1000000, 1000000],
|
|
'Readiness did not retry a transient startup race with bounded backoff.');
|
|
|
|
$now = 20.0;
|
|
$attempts = 0;
|
|
$sleeps = [];
|
|
$ready = CloudAgentReadiness::wait(
|
|
static function () use (&$attempts): bool {
|
|
$attempts++;
|
|
throw new RuntimeException('SECRET transport detail');
|
|
},
|
|
1.5,
|
|
static function () use (&$now): float {
|
|
return $now;
|
|
},
|
|
static function (int $microseconds) use (&$now, &$sleeps): void {
|
|
$sleeps[] = $microseconds;
|
|
$now += $microseconds / 1000000;
|
|
},
|
|
);
|
|
$assert(!$ready && $attempts === 3 && $sleeps === [1000000, 500000],
|
|
'Readiness did not stop at its monotonic deadline after probe failures.');
|
|
|
|
$root = dirname(__DIR__);
|
|
$readiness = file_get_contents($root . '/app/Services/Cloud/CloudAgentReadiness.php');
|
|
$lifecycle = file_get_contents($root . '/app/Command/CloudLifecycle.php');
|
|
$lifecycleService = file_get_contents($root . '/app/Services/Cloud/CloudLifecycleService.php');
|
|
$worker = file_get_contents($root . '/app/Command/CloudWorker.php');
|
|
$heartbeat = file_get_contents($root . '/app/Services/Cloud/CloudRuntimeHeartbeat.php');
|
|
$assert(str_contains($readiness, 'CloudAgentRegistryHealthService::fromConfig()')
|
|
&& str_contains($readiness, "['status'] ?? null")
|
|
&& !str_contains($readiness, 'CloudEngineClient')
|
|
&& !str_contains($readiness, 'ssh'),
|
|
'The production gate is not a bounded Go Agent liveness probe.');
|
|
$assert(str_contains($heartbeat, "'engine_readiness' => '等待 Go Agent 就绪'")
|
|
&& str_contains($heartbeat, "'engine_readiness_timeout'"),
|
|
'Readiness observations are not allowlisted by runtime health telemetry.');
|
|
$assert(str_contains($lifecycle, '$service->tick(200, $skipThisTick)')
|
|
&& substr_count($lifecycleService, 'if (!$skipEngineObservations)') === 2
|
|
&& str_contains($lifecycleService, "observeFailure('engine_readiness_timeout')"),
|
|
'A readiness timeout can still run first-pass Agent observations.');
|
|
foreach ([$lifecycle, $worker] as $source) {
|
|
$assert(str_contains($source, 'if (!$once)')
|
|
&& str_contains($source, 'CloudAgentReadiness::wait()')
|
|
&& str_contains($source, "engine_readiness_timeout"),
|
|
'A long-running consumer lost its Agent readiness gate.');
|
|
}
|
|
$assert(str_contains($worker, 'self::deliverNotifications($heartbeat)')
|
|
&& str_contains($worker, '?callable $engineReadiness = null'),
|
|
'An Agent-readiness failure can still suppress DB-backed notifications.');
|
|
|
|
echo "Go Agent consumer readiness checks passed.\n";
|