fail('Could not create the spawn counter file.'); } $this->counter = $counter; file_put_contents($this->counter, '0'); } protected function tearDown(): void { parent::tearDown(); @unlink($this->counter); } #[TestDox('a failed attempt is retried against a newly spawned server')] public function testRetrySpawnsAnotherServer(): void { $client = $this->connect( 'retry', $this->clientBuilder()->setInitTimeout(2)->setMaxRetries(1), $this->environment(failing: 1), ); $this->assertSame(2, $this->spawns()); $this->assertTrue($client->isConnected()); $this->assertSame('quick', $client->callTool('fast')->content[0]->text ?? null); } #[TestDox('no retries means the first failure is the last word')] public function testRetriesCanBeDisabled(): void { $client = $this->clientBuilder()->setInitTimeout(2)->setMaxRetries(0)->build(); try { $client->connect($this->transport('retry', $this->environment(failing: 1))); $this->fail('Connecting should not have succeeded.'); } catch (ConnectionException) { $this->assertSame(1, $this->spawns()); } } /** * @return array */ private function environment(int $failing): array { return [ 'MCP_SPAWN_COUNTER' => $this->counter, 'MCP_FAIL_SPAWNS' => (string) $failing, ]; } private function spawns(): int { return (int) file_get_contents($this->counter); } }