Fix ConnectionErrorProof response count on single node read errors (#1739)

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
This commit is contained in:
dualfrozandTill Krüss committed 2026-10-08 09:34:40 -07:00
1 parent 839ef60ab2
commit 343a812a2b
3 files changed
+63 -6

No files matched your search

@@ -138,6 +138,62 @@ class ConnectionErrorProofTest extends PredisTestCase
$pipeline->execute();
}
/**
* @dataProvider singleConnectionReadFailureProvider
* @group disconnected
*/
public function testReturnsExceptionForFailedAndRemainingCommandsOnReadFailureWithSingleConnection(
int $sizeOfPipe,
int $failingIndex
): void {
$connection = $this->getMockConnection('tcp://127.0.0.1:7001');
$exception = new ConnectionException($connection, 'Connection lost');
$readResponses = [];
$expectedResponses = [];
for ($i = 0; $i < $sizeOfPipe; ++$i) {
if ($i < $failingIndex) {
$readResponses[] = "value$i";
$expectedResponses[] = "value$i";
} else {
$expectedResponses[] = $exception;
}
}
$readResponses[] = $this->throwException($exception);
$connection
->expects($this->once())
->method('write');
$connection
->expects($this->exactly($failingIndex + 1))
->method('readResponse')
->willReturnOnConsecutiveCalls(...$readResponses);
$pipeline = new ConnectionErrorProof(new Client($connection));
for ($i = 0; $i < $sizeOfPipe; ++$i) {
$pipeline->echo("value$i");
}
$responses = $pipeline->execute();
$this->assertCount($sizeOfPipe, $responses);
$this->assertSame($expectedResponses, $responses);
}
public function singleConnectionReadFailureProvider(): array
{
return [
'single command' => [1, 0],
'first of three' => [3, 0],
'second of three' => [3, 1],
'last of three' => [3, 2],
'fourth of five' => [5, 3],
];
}
/**
* Returns a mocked cluster connection routing commands by their first key.
*