Skip to content

Commit 97cc43b

Browse files
committed
add test to ensure we don't throw an error when the connection times out
1 parent eb373eb commit 97cc43b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/Impl/Integrations/GuzzleFeatureRequesterTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,37 @@ public function testSendsCorrectWrapperNameHeaders(?string $wrapper_name, ?strin
144144
$this->assertNotContains('X-LaunchDarkly-Wrapper', $headers);
145145
}
146146
}
147+
148+
public function testTimeoutReturnsDefaultValue(): void
149+
{
150+
/** @var LoggerInterface **/
151+
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
152+
153+
$config = [
154+
'logger' => $logger,
155+
'timeout' => 1, // Set a very short timeout
156+
'connect_timeout' => 1,
157+
];
158+
159+
$client = new Client();
160+
// Configure the mock server to delay the response by 2 seconds
161+
$delayRule = [
162+
'request' => [
163+
'url' => '/sdk/flags/delayed-flag',
164+
],
165+
'response' => [
166+
'fixedDelayMilliseconds' => 2000,
167+
'status' => 200,
168+
'body' => '{"key": "delayed-flag", "version": 1}'
169+
]
170+
];
171+
172+
$client->request('POST', 'http://localhost:8080/__admin/mappings', ['json' => $delayRule]);
173+
174+
$requester = new GuzzleFeatureRequester('http://localhost:8080', 'sdk-key', $config);
175+
$result = $requester->getFeature("delayed-flag");
176+
177+
// The request should timeout and return null (default value) instead of throwing an exception
178+
$this->assertNull($result);
179+
}
147180
}

0 commit comments

Comments
 (0)