Add a connected Sentinel replicas test
This commit is contained in:
1 parent
6ea16b84c7
commit
dcae90b874
1 file changed
+34
@@ -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 ------------------------------------------------ //
|
||||
// ******************************************************************** //
|
||||
|
||||
Reference in new issue
Block a user