fix(vpc): serialize host route dispatch
parent
4640b8d869
commit
1694a972bc
@ -0,0 +1,93 @@
|
||||
<?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->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',
|
||||
'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.');
|
||||
|
||||
$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";
|
||||
Loading…
Reference in New Issue