|
|
|
|
@ -36,6 +36,10 @@ foreach ([
|
|
|
|
|
"scope_type IN ('instance','host','public_ip_pool')",
|
|
|
|
|
'compensation_seconds BETWEEN 1 AND 31622400',
|
|
|
|
|
'AND attempts <= 8 AND available_at > 0',
|
|
|
|
|
'AND service_period_id IS NOT NULL',
|
|
|
|
|
'AND after_period_ends_at IS NOT NULL',
|
|
|
|
|
'AND after_traffic_ends_at IS NOT NULL',
|
|
|
|
|
'AND after_backup_ends_at IS NOT NULL',
|
|
|
|
|
'AND audit_job_id IS NOT NULL',
|
|
|
|
|
"kind = 'service_compensation'",
|
|
|
|
|
] as $contract) {
|
|
|
|
|
@ -100,4 +104,78 @@ $assert(str_contains($setup,
|
|
|
|
|
"SCHEMA_VERSION = 'go-agent-wss-v35-service-compensations'"),
|
|
|
|
|
'CloudSetup schema version was not advanced for service compensation.');
|
|
|
|
|
|
|
|
|
|
$appliedShape = preg_match(
|
|
|
|
|
'/CONSTRAINT chk_cloud_service_compensation_item_applied CHECK \((.*?)\n \),\n CONSTRAINT chk_cloud_service_compensation_item_error/s',
|
|
|
|
|
$schema,
|
|
|
|
|
$appliedMatch
|
|
|
|
|
) === 1 ? $appliedMatch[1] : '';
|
|
|
|
|
$assert($appliedShape !== '',
|
|
|
|
|
'Applied compensation CHECK could not be extracted for insertion tests.');
|
|
|
|
|
$probe = new PDO('sqlite::memory:');
|
|
|
|
|
$probe->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
$probe->exec('CREATE TABLE applied_compensation_probe (
|
|
|
|
|
state TEXT NOT NULL,
|
|
|
|
|
requested_seconds INTEGER NOT NULL,
|
|
|
|
|
service_period_id INTEGER NULL,
|
|
|
|
|
applied_at INTEGER NULL,
|
|
|
|
|
before_expires_at INTEGER NULL,
|
|
|
|
|
after_expires_at INTEGER NULL,
|
|
|
|
|
before_period_ends_at INTEGER NULL,
|
|
|
|
|
after_period_ends_at INTEGER NULL,
|
|
|
|
|
before_traffic_ends_at INTEGER NULL,
|
|
|
|
|
after_traffic_ends_at INTEGER NULL,
|
|
|
|
|
before_backup_ends_at INTEGER NULL,
|
|
|
|
|
after_backup_ends_at INTEGER NULL,
|
|
|
|
|
after_snapshot_json TEXT NULL,
|
|
|
|
|
audit_job_id INTEGER NULL,
|
|
|
|
|
last_error_code TEXT NOT NULL,
|
|
|
|
|
last_error TEXT NOT NULL,
|
|
|
|
|
CHECK (' . $appliedShape . ')
|
|
|
|
|
)');
|
|
|
|
|
$columns = [
|
|
|
|
|
'state', 'requested_seconds', 'service_period_id', 'applied_at',
|
|
|
|
|
'before_expires_at', 'after_expires_at', 'before_period_ends_at',
|
|
|
|
|
'after_period_ends_at', 'before_traffic_ends_at',
|
|
|
|
|
'after_traffic_ends_at', 'before_backup_ends_at',
|
|
|
|
|
'after_backup_ends_at', 'after_snapshot_json', 'audit_job_id',
|
|
|
|
|
'last_error_code', 'last_error',
|
|
|
|
|
];
|
|
|
|
|
$statement = $probe->prepare('INSERT INTO applied_compensation_probe ('
|
|
|
|
|
. implode(', ', $columns) . ') VALUES (:'
|
|
|
|
|
. implode(', :', $columns) . ')');
|
|
|
|
|
$valid = [
|
|
|
|
|
'state' => 'applied', 'requested_seconds' => 60,
|
|
|
|
|
'service_period_id' => 7, 'applied_at' => 100,
|
|
|
|
|
'before_expires_at' => 1000, 'after_expires_at' => 1060,
|
|
|
|
|
'before_period_ends_at' => 1000, 'after_period_ends_at' => 1060,
|
|
|
|
|
'before_traffic_ends_at' => null, 'after_traffic_ends_at' => null,
|
|
|
|
|
'before_backup_ends_at' => null, 'after_backup_ends_at' => null,
|
|
|
|
|
'after_snapshot_json' => '{}', 'audit_job_id' => 8,
|
|
|
|
|
'last_error_code' => '', 'last_error' => '',
|
|
|
|
|
];
|
|
|
|
|
$statement->execute($valid);
|
|
|
|
|
$expectRejected = static function (array $changes) use (
|
|
|
|
|
$assert,
|
|
|
|
|
$statement,
|
|
|
|
|
$valid
|
|
|
|
|
): void {
|
|
|
|
|
try {
|
|
|
|
|
$statement->execute(array_replace($valid, $changes));
|
|
|
|
|
} catch (PDOException $error) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$assert(false, 'Applied compensation CHECK accepted incomplete evidence: '
|
|
|
|
|
. implode(', ', array_keys($changes)));
|
|
|
|
|
};
|
|
|
|
|
$expectRejected(['service_period_id' => null]);
|
|
|
|
|
$expectRejected(['after_period_ends_at' => null]);
|
|
|
|
|
$expectRejected([
|
|
|
|
|
'before_traffic_ends_at' => 1000,
|
|
|
|
|
'after_traffic_ends_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
$expectRejected([
|
|
|
|
|
'before_backup_ends_at' => 1000,
|
|
|
|
|
'after_backup_ends_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
echo "Service compensation schema contracts passed.\n";
|
|
|
|
|
|