diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index ef1de09..826ac43 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Predis\Command\Factory as CommandFactory; use Predis\Command\Processor\KeyPrefixProcessor; use Predis\Command\RawCommand; +use Predis\Command\Redis\Utils\CommandUtility; use Predis\Connection\Cluster\RedisCluster; use Predis\Connection\Factory; use Predis\Connection\NodeConnectionInterface; @@ -1745,6 +1746,39 @@ class ClientTest extends PredisTestCase $this->assertEquals('sentinel_resp3_test_value', $client->get('sentinel_resp3_test_key')); } + /** + * @group connected + * @group sentinel + * @group relay-incompatible + */ + public function testSentinelReplicationDiscoversReplicasReportedBySentinel(): void + { + $client = $this->createClient(); + $connection = $client->getConnection(); + + $this->assertInstanceOf(SentinelReplication::class, $connection); + + // SENTINEL SLAVES is understood by every Sentinel version, so it is the + // reference for what SENTINEL REPLICAS (or the fallback to SENTINEL + // SLAVES on Redis < 5.0) has to discover. + $reportedReplicas = $connection->getSentinelConnection()->executeCommand( + RawCommand::create('SENTINEL', 'slaves', constant('REDIS_SENTINEL_SERVICE')) + ); + + $expectedReplicas = array_map(static function (array $replica): string { + $replica = CommandUtility::arrayToDictionary($replica, null, false); + + return "{$replica['ip']}:{$replica['port']}"; + }, $reportedReplicas); + + $discoveredReplicas = array_map('strval', $connection->getSlaves()); + + sort($expectedReplicas); + sort($discoveredReplicas); + + $this->assertSame($expectedReplicas, $discoveredReplicas); + } + // ******************************************************************** // // ---- HELPER METHODS ------------------------------------------------ // // ******************************************************************** //