Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcacb7f

Browse files
committed
Fix Integration tests skipped with Redis cluster
1 parent 0900333 commit fcacb7f

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
ports:
5050
- 16379:6379
5151
redis-cluster:
52-
image: grokzen/redis-cluster:latest
52+
image: grokzen/redis-cluster:6.0.0
5353
ports:
5454
- 7000:7000
5555
- 7001:7001

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function setUp(): void
3636

3737
try {
3838
$this->redis = new \Redis();
39-
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')], $this->redis);
39+
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);
4040
$this->connection->cleanup();
4141
$this->connection->setup();
4242
} catch (\Exception $e) {
@@ -144,7 +144,7 @@ public function testConnectionSendDelayedMessagesWithSameContent()
144144
public function testConnectionBelowRedeliverTimeout()
145145
{
146146
// lower redeliver timeout and claim interval
147-
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')], $this->redis);
147+
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);
148148

149149
$connection->cleanup();
150150
$connection->setup();
@@ -172,7 +172,7 @@ public function testConnectionClaimAndRedeliver()
172172
// lower redeliver timeout and claim interval
173173
$connection = Connection::fromDsn(
174174
getenv('MESSENGER_REDIS_DSN'),
175-
['redeliver_timeout' => 0, 'claim_interval' => 500, 'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')],
175+
['redeliver_timeout' => 0, 'claim_interval' => 500, 'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null],
176176

177177
$this->redis
178178
);
@@ -222,7 +222,8 @@ public function testLazySentinel()
222222
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'),
223223
['lazy' => true,
224224
'delete_after_ack' => true,
225-
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER'), ], $this->redis);
225+
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
226+
], $this->redis);
226227

227228
$connection->add('1', []);
228229
$this->assertNotEmpty($message = $connection->get());
@@ -240,11 +241,7 @@ public function testLazyCluster()
240241
{
241242
$this->skipIfRedisClusterUnavailable();
242243

243-
$connection = new Connection(
244-
['lazy' => true],
245-
['host' => explode(' ', getenv('REDIS_CLUSTER_HOSTS'))],
246-
[]
247-
);
244+
$connection = new Connection(['lazy' => true, 'host' => explode(' ', getenv('REDIS_CLUSTER_HOSTS'))]);
248245

249246
$connection->add('1', []);
250247
$this->assertNotEmpty($message = $connection->get());
@@ -293,7 +290,7 @@ public function testFromDsnWithMultipleHosts()
293290
$dsn = array_map(fn ($host) => 'redis://'.$host, $hosts);
294291
$dsn = implode(',', $dsn);
295292

296-
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')]));
293+
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null]));
297294
}
298295

299296
public function testJsonError()

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static function initializeRedis(\Redis|Relay $redis, string $host, int $
154154
*/
155155
private static function initializeRedisCluster(?\RedisCluster $redis, array $hosts, string|array|null $auth, array $params): \RedisCluster
156156
{
157-
$redis ??= new \RedisCluster(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $auth, ...\defined('Redis::SCAN_PREFIX') ? [$params['ssl'] ?? null] : []);
157+
$redis ??= new \RedisCluster(null, $hosts, $params['timeout'], $params['read_timeout'], isset($params['persistent_id']), $auth, ...\defined('Redis::SCAN_PREFIX') ? [$params['ssl'] ?? null] : []);
158158
$redis->setOption(\Redis::OPT_SERIALIZER, $params['serializer']);
159159

160160
return $redis;

0 commit comments

Comments
 (0)