Add timeout settings for Shelly cloud HTTP requests and update related tests
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -16,6 +16,8 @@ class shelly implements shelly_i
|
||||
private const SHELLY_RATE_LIMIT_WAIT_TIMEOUT_SECONDS = 20;
|
||||
private const SHELLY_RATE_LIMIT_WINDOW_MILLISECONDS = 2000;
|
||||
private const SHELLY_RATE_LIMIT_GATE_KEY = 'shelly_cloud_rate_limit_gate';
|
||||
private const SHELLY_CONNECT_TIMEOUT_SECONDS = 2;
|
||||
private const SHELLY_REQUEST_TIMEOUT_SECONDS = 5;
|
||||
/**
|
||||
* @var array<int,array<string,mixed>>
|
||||
*/
|
||||
@@ -178,6 +180,9 @@ class shelly implements shelly_i
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::SHELLY_CONNECT_TIMEOUT_SECONDS);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, self::SHELLY_REQUEST_TIMEOUT_SECONDS);
|
||||
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
|
||||
// Execute the request
|
||||
$response = curl_exec($ch);
|
||||
// Get the status code
|
||||
@@ -224,6 +229,9 @@ class shelly implements shelly_i
|
||||
);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::SHELLY_CONNECT_TIMEOUT_SECONDS);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, self::SHELLY_REQUEST_TIMEOUT_SECONDS);
|
||||
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
@@ -336,7 +336,6 @@ trait selfserve_lane_command_t
|
||||
protected function runRelaySideEffectsForWashStart(selfserve_lane_command_arguments $arguments): void
|
||||
{
|
||||
if ($arguments->defer_relay_side_effects) {
|
||||
$this->setProgramPickerRelayStatusForWashStart();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,17 +109,15 @@ it('parses deferred relay side effects on start command arguments', function ():
|
||||
expect($arguments->defer_relay_side_effects)->toBeTrue();
|
||||
});
|
||||
|
||||
it('syncs only the program picker relay when start asks to defer machine side effects', function (): void {
|
||||
it('skips relay side effects when start asks to defer machine side effects', function (): void {
|
||||
$lane = new SelfserveLaneStartEntranceTimeoutHarness();
|
||||
|
||||
$lane->runStartRelaySideEffects(true);
|
||||
|
||||
expect($lane->cleanerRelayCalls)->toBe(0);
|
||||
expect($lane->programPickerRelayCalls)->toBe(1);
|
||||
expect($lane->programPickerRelayCalls)->toBe(0);
|
||||
expect($lane->machineRelayCalls)->toBe(0);
|
||||
expect($lane->relayEvents)->toBe([
|
||||
'program_picker:sync',
|
||||
]);
|
||||
expect($lane->relayEvents)->toBe([]);
|
||||
});
|
||||
|
||||
it('keeps cleaner, program picker and machine relay side effects in order for normal start commands', function (): void {
|
||||
|
||||
@@ -14,6 +14,17 @@ it('enforces a global 2 second Shelly gate in sendPostRequest', function (): voi
|
||||
expect($sendPostRequestBody)->toContain('$this->waitForShellyRateLimitWindow();');
|
||||
});
|
||||
|
||||
it('bounds Shelly cloud HTTP requests with curl timeouts', function (): void {
|
||||
$shellyClass = file_get_contents(app_path('classes/shelly.php'));
|
||||
|
||||
expect($shellyClass)->not->toBeFalse();
|
||||
expect($shellyClass)->toContain('private const SHELLY_CONNECT_TIMEOUT_SECONDS = 2;');
|
||||
expect($shellyClass)->toContain('private const SHELLY_REQUEST_TIMEOUT_SECONDS = 5;');
|
||||
expect($shellyClass)->toContain('CURLOPT_CONNECTTIMEOUT, self::SHELLY_CONNECT_TIMEOUT_SECONDS');
|
||||
expect($shellyClass)->toContain('CURLOPT_TIMEOUT, self::SHELLY_REQUEST_TIMEOUT_SECONDS');
|
||||
expect($shellyClass)->toContain('CURLOPT_NOSIGNAL, true');
|
||||
});
|
||||
|
||||
it('uses Redis NX PX semantics for cross-request Shelly rate limiting', function (): void {
|
||||
$shellyClass = file_get_contents(app_path('classes/shelly.php'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user