|
11 | 11 | use function gzdecode; |
12 | 12 | use function gzencode; |
13 | 13 | use InvalidArgumentException; |
| 14 | +use Nyholm\Psr7\Request; |
14 | 15 | use Nyholm\Psr7\Response; |
15 | 16 | use OpenTelemetry\SDK\Common\Export\Http\PsrTransport; |
16 | 17 | use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory; |
17 | 18 | use PHPUnit\Framework\Attributes\CoversClass; |
18 | 19 | use PHPUnit\Framework\MockObject\MockObject; |
19 | 20 | use PHPUnit\Framework\TestCase; |
20 | 21 | use Psr\Http\Client\ClientInterface; |
| 22 | +use Psr\Http\Client\NetworkExceptionInterface; |
21 | 23 | use Psr\Http\Message\RequestInterface; |
22 | 24 | use Psr\Http\Message\ResponseInterface; |
23 | 25 |
|
@@ -152,6 +154,28 @@ public function test_send_number_of_retries(): void |
152 | 154 | $response->await(); |
153 | 155 | } |
154 | 156 |
|
| 157 | + public function test_send_retry_network_exception_returns_error(): void |
| 158 | + { |
| 159 | + $e = new class('network error') extends \Exception implements NetworkExceptionInterface { |
| 160 | + public function getRequest(): RequestInterface |
| 161 | + { |
| 162 | + return new Request('GET', 'http://localhost'); |
| 163 | + } |
| 164 | + }; |
| 165 | + $this->client->expects($this->exactly(4))->method('sendRequest')->willThrowException($e); |
| 166 | + $transport = $this->factory->create('http://localhost', 'text/plain', [], null, 10., 100, 3); |
| 167 | + |
| 168 | + $response = $transport->send(''); |
| 169 | + |
| 170 | + try { |
| 171 | + $response->await(); |
| 172 | + } catch (Exception $e) { |
| 173 | + $this->assertStringContainsString('retry limit', $e->getMessage()); |
| 174 | + $this->assertNotNull($e->getPrevious()); |
| 175 | + $this->assertSame('network error', $e->getPrevious()->getMessage()); |
| 176 | + } |
| 177 | + } |
| 178 | + |
155 | 179 | public function test_send_exception_returns_error(): void |
156 | 180 | { |
157 | 181 | $this->client->expects($this->once())->method('sendRequest')->willThrowException(new Exception()); |
|
0 commit comments