|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Models\CloudJob;
|
|
|
|
|
use App\Services\Cloud\CloudJobService;
|
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$capsule = new Capsule();
|
|
|
|
|
$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'],
|
|
|
|
|
'default');
|
|
|
|
|
$capsule->setAsGlobal();
|
|
|
|
|
$capsule->bootEloquent();
|
|
|
|
|
$capsule->schema('default')->create('cloud_jobs', static function (
|
|
|
|
|
Blueprint $table
|
|
|
|
|
): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->integer('host_id')->nullable();
|
|
|
|
|
$table->string('kind');
|
|
|
|
|
$table->string('phase');
|
|
|
|
|
$table->integer('vpc_repair_root_job_id')->nullable();
|
|
|
|
|
$table->string('effect_resolution')->default('not_applicable');
|
|
|
|
|
$table->boolean('finalization_incident')->default(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$insert = static function (int $id, int $hostId, string $kind): void {
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'host_id' => $hostId,
|
|
|
|
|
'kind' => $kind,
|
|
|
|
|
'phase' => 'accepted',
|
|
|
|
|
'vpc_repair_root_job_id' => null,
|
|
|
|
|
'effect_resolution' => 'not_applicable',
|
|
|
|
|
'finalization_incident' => 0,
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
$insert(1, 10, 'vpc_host_apply');
|
|
|
|
|
$insert(2, 10, 'vpc_host_remove');
|
|
|
|
|
$insert(3, 11, 'vpc_host_apply');
|
|
|
|
|
$insert(4, 10, 'vpc_port_attach');
|
|
|
|
|
$insert(5, 10, 'vpc_host_apply');
|
|
|
|
|
|
|
|
|
|
$eligibleIds = static function (): array {
|
|
|
|
|
$query = CloudJob::query()->where('phase', 'accepted');
|
|
|
|
|
CloudJobService::applyVpcHostDispatchFence($query);
|
|
|
|
|
return $query->orderBy('id')->pluck('id')->map(
|
|
|
|
|
static fn ($id): int => (int) $id
|
|
|
|
|
)->all();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$assert($eligibleIds() === [1, 3, 4],
|
|
|
|
|
'Same-host route successors were not serialized by durable job order.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 1)->update([
|
|
|
|
|
'phase' => 'terminal',
|
|
|
|
|
'effect_resolution' => 'not_applied',
|
|
|
|
|
]);
|
|
|
|
|
$assert($eligibleIds() === [2, 3, 4],
|
|
|
|
|
'Known-not-applied predecessor did not release the next host route job.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 1)->update([
|
|
|
|
|
'effect_resolution' => 'unknown',
|
|
|
|
|
]);
|
|
|
|
|
$assert($eligibleIds() === [3, 4],
|
|
|
|
|
'Unknown-effect route predecessor did not fence its host lane.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 1)->update([
|
|
|
|
|
'effect_resolution' => 'applied',
|
|
|
|
|
'finalization_incident' => 1,
|
|
|
|
|
]);
|
|
|
|
|
$assert($eligibleIds() === [3, 4],
|
|
|
|
|
'Finalization incident did not retain the host route fence.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 1)->update([
|
|
|
|
|
'finalization_incident' => 0,
|
|
|
|
|
]);
|
|
|
|
|
$assert($eligibleIds() === [2, 3, 4],
|
|
|
|
|
'Resolved route predecessor did not release exactly one host successor.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
['id' => 6, 'host_id' => 20, 'kind' => 'vpc_host_apply',
|
|
|
|
|
'phase' => 'terminal', 'effect_resolution' => 'unknown',
|
|
|
|
|
'finalization_incident' => 0, 'vpc_repair_root_job_id' => null],
|
|
|
|
|
['id' => 7, 'host_id' => 20, 'kind' => 'vpc_host_apply',
|
|
|
|
|
'phase' => 'terminal', 'effect_resolution' => 'unknown',
|
|
|
|
|
'finalization_incident' => 0, 'vpc_repair_root_job_id' => 6],
|
|
|
|
|
['id' => 8, 'host_id' => 20, 'kind' => 'vpc_host_apply',
|
|
|
|
|
'phase' => 'accepted', 'effect_resolution' => 'not_applicable',
|
|
|
|
|
'finalization_incident' => 0, 'vpc_repair_root_job_id' => 6],
|
|
|
|
|
]);
|
|
|
|
|
$assert(in_array(8, $eligibleIds(), true),
|
|
|
|
|
'An exact VPC repair successor could not cross its own predecessor chain.');
|
|
|
|
|
|
|
|
|
|
$worker = file_get_contents(
|
|
|
|
|
dirname(__DIR__) . '/app/Services/Cloud/CloudWorkerService.php'
|
|
|
|
|
);
|
|
|
|
|
$assert(is_string($worker)
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
'CloudJobService::applyVpcHostDispatchFence($query);'),
|
|
|
|
|
'The worker claim path does not apply the host VPC dispatch fence.');
|
|
|
|
|
|
|
|
|
|
echo "Host-scoped VPC route dispatch queue passed.\n";
|