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

45 lines
1.9 KiB
PHP

<?php
$root = dirname(__DIR__);
$policy = file_get_contents(
$root . '/app/Services/Cloud/CloudInstanceNetworkPolicy.php'
);
$accounting = file_get_contents(
$root . '/app/Services/Cloud/CloudTrafficPoolAccounting.php'
);
if (!is_string($policy) || !is_string($accounting)) {
throw new RuntimeException('Unable to read traffic policy sources.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(!str_contains($accounting, 'CloudInstanceNetworkPolicy')
&& !str_contains($accounting, 'CloudInstanceNetworkRestriction')
&& !str_contains($accounting, 'CloudInstanceNetworkPolicyState')
&& !str_contains($accounting, 'CloudAgentClient'),
'Pool accounting crossed into the instance policy/Agent lock domain.');
$assert(str_contains($policy, 'lockState($instance, $now)')
&& str_contains($policy, 'lockRestrictions((int) $instance->id)')
&& strpos($policy, 'lockState($instance, $now)')
< strpos($policy, 'lockRestrictions((int) $instance->id)'),
'Network policy no longer locks state before ordered reasons.');
$assert(str_contains($policy, "orderBy('reason_code')->lockForUpdate()"),
'Network restriction rows are not locked in reason-code order.');
$poolRead = strpos($policy, '$pool = CloudTrafficPool::where(');
$poolReadEnd = $poolRead === false ? false
: strpos($policy, ')->first();', $poolRead);
$assert($poolRead !== false && $poolReadEnd !== false
&& !str_contains(
substr($policy, $poolRead, $poolReadEnd - $poolRead),
'lockForUpdate'
),
'Network policy acquired a traffic-pool write lock.');
$assert(!str_contains($policy, 'CloudAgentClient')
&& !str_contains($policy, 'CloudJobService'),
'Network policy gained a remote side effect or queue dependency.');
echo "Cloud traffic restriction lock-order contract passed.\n";