* [Client] Implement setMaxRetries connection retries * [Client] Reject a negative retry count in Configuration * [Client] Use a positive init timeout in the retry test * [Client] Drop redundant docblock note on setMaxRetries * [Client] Clear the initialized flag on a failed connection * [Client] Trim comments to the non-obvious ones * [Client] Cover retries and timeout cleanup with integration tests The retry fixture counts the processes it was started as, which is what separates a real retry from a second call into the same server. The timeout fixture outlives the client's patience and then goes idle, so the next request runs on a connection the client already gave up on once.
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the official PHP MCP SDK.
|
|
*
|
|
* A collaboration between Symfony and the PHP Foundation.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Mcp\Tests\Integration;
|
|
|
|
use Mcp\Exception\RequestException;
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
/**
|
|
* What a timed-out request leaves behind on the connection.
|
|
*
|
|
* @see Fixture/request_timeout.php for the server under test
|
|
*/
|
|
final class RequestTimeoutTest extends IntegrationTestCase
|
|
{
|
|
#[TestDox('an abandoned response is not handed to the next request')]
|
|
public function testTimedOutRequestDoesNotLeakIntoTheNext(): void
|
|
{
|
|
$client = $this->connect('request_timeout', $this->clientBuilder()->setRequestTimeout(1));
|
|
|
|
try {
|
|
$client->callTool('slow');
|
|
$this->fail('The slow tool should have outlived the request timeout.');
|
|
} catch (RequestException) {
|
|
}
|
|
|
|
// The server is still executing the abandoned call and cannot answer
|
|
// anything until it returns, so the next request has to wait it out.
|
|
sleep(2);
|
|
|
|
// Without the pending request being cleared this answers 'late': the
|
|
// response the client gave up on, handed to the request after it.
|
|
$this->assertSame('quick', $client->callTool('fast')->content[0]->text ?? null);
|
|
}
|
|
}
|