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

72 lines
2.3 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudObjectStorageBackendRegistry;
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);
}
};
$source = file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudBackupService.php'
);
$assert(is_string($source)
&& str_contains(
$source,
'CloudObjectStorageBackendRegistry::summary()'
)
&& str_contains($source, "['writable_backends']")
&& !str_contains($source, 'CloudObjectStorageConfig::view()'),
'Backup availability still depends on the retired singleton storage view.');
$db = new Capsule();
$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
], 'default');
$db->setAsGlobal();
$db->bootEloquent();
$db->schema('default')->create(
'cloud_storage_backends',
static function (Blueprint $table): void {
$table->increments('id');
$table->string('admin_state');
$table->string('health_state');
$table->unsignedBigInteger('config_revision');
$table->unsignedBigInteger('tested_revision');
}
);
Capsule::table('cloud_storage_backends')->insert([
'id' => 1,
'admin_state' => 'active',
'health_state' => 'healthy',
'config_revision' => 3,
'tested_revision' => 3,
]);
$summary = CloudObjectStorageBackendRegistry::summary();
$assert((int) $summary['writable_backends'] === 1,
'A current active healthy backend was not writable for backup creation.');
Capsule::table('cloud_storage_backends')->where('id', 1)->update([
'tested_revision' => 2,
]);
$summary = CloudObjectStorageBackendRegistry::summary();
$assert((int) $summary['writable_backends'] === 0,
'A stale backend revision remained writable for backup creation.');
Capsule::table('cloud_storage_backends')->where('id', 1)->update([
'tested_revision' => 3,
'health_state' => 'unreachable',
]);
$summary = CloudObjectStorageBackendRegistry::summary();
$assert((int) $summary['writable_backends'] === 0,
'An unreachable backend remained writable for backup creation.');
echo "Backup multi-backend availability behavior passed.\n";