Skip to content

Commit b04eb43

Browse files
committed
minor symfony#61655 [Messenger] fix setup to actually run Redis Sentinel/Cluster integration tests (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Messenger] fix setup to actually run Redis Sentinel/Cluster integration tests | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT while looking into symfony#61590 I realised that we didn't properly set the needed environment variables to run the Sentinel related integration tests Commits ------- c47eaba fix setup to actually run Redis Sentinel/Cluster integration tests
2 parents c5ac440 + c47eaba commit b04eb43

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ jobs:
261261
REDIS_SENTINEL_SERVICE: redis_sentinel
262262
REDIS_REPLICATION_HOSTS: 'localhost:16382 localhost:16381'
263263
MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages
264+
MESSENGER_REDIS_SENTINEL_MASTER: redis_sentinel
264265
MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages
265266
MESSENGER_SQS_DSN: "sqs://localhost:4566/messages?sslmode=disable&poll_timeout=0.01"
266267
MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:4566/messages.fifo?sslmode=disable&poll_timeout=0.01"

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,19 @@ public static function provideIdPatterns(): \Generator
403403
yield '100ms delay' => ['/^\w+\.\d+$/', 100, 'rawCommand', '1'];
404404
}
405405

406+
/**
407+
* @group integration
408+
*/
406409
public function testInvalidSentinelMasterName()
407410
{
411+
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) {
412+
$this->markTestSkipped('REDIS_SENTINEL_HOSTS env var is not defined.');
413+
}
414+
415+
$dsn = 'redis:?host['.str_replace(' ', ']&host[', $hosts).']';
416+
408417
try {
409-
Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['delete_after_ack' => true], null);
418+
Connection::fromDsn($dsn, ['delete_after_ack' => true]);
410419
} catch (\Exception $e) {
411420
self::markTestSkipped($e->getMessage());
412421
}
@@ -415,14 +424,12 @@ public function testInvalidSentinelMasterName()
415424
self::markTestSkipped('Redis sentinel is not configured');
416425
}
417426

418-
$master = getenv('MESSENGER_REDIS_DSN');
419427
$uid = uniqid('sentinel_', true);
420428

421-
$exp = explode('://', $master, 2)[1];
422429
$this->expectException(\InvalidArgumentException::class);
423-
$this->expectExceptionMessage(\sprintf('Failed to retrieve master information from master name "%s" and address "%s".', $uid, $exp));
430+
$this->expectExceptionMessage(\sprintf('Failed to retrieve master information from sentinel "%s".', $uid));
424431

425-
Connection::fromDsn(\sprintf('%s/messenger-clearlasterror', $master), ['delete_after_ack' => true, 'sentinel_master' => $uid], null);
432+
Connection::fromDsn(\sprintf('%s/messenger-clearlasterror', $dsn), ['delete_after_ack' => true, 'sentinel_master' => $uid]);
426433
}
427434

428435
public function testFromDsnOnUnixSocketWithUserAndPassword()

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp(): void
3939

4040
try {
4141
$this->redis = $this->createRedisClient();
42-
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);
42+
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);
4343
$this->connection->cleanup();
4444
$this->connection->setup();
4545
} catch (\Exception $e) {
@@ -147,7 +147,7 @@ public function testConnectionSendDelayedMessagesWithSameContent()
147147
public function testConnectionBelowRedeliverTimeout()
148148
{
149149
// lower redeliver timeout and claim interval
150-
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);
150+
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);
151151

152152
$connection->cleanup();
153153
$connection->setup();
@@ -175,7 +175,7 @@ public function testConnectionClaimAndRedeliver()
175175
// lower redeliver timeout and claim interval
176176
$connection = Connection::fromDsn(
177177
getenv('MESSENGER_REDIS_DSN'),
178-
['redeliver_timeout' => 0, 'claim_interval' => 500, 'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null],
178+
['redeliver_timeout' => 0, 'claim_interval' => 500],
179179

180180
$this->redis
181181
);
@@ -251,7 +251,17 @@ public function testSentinel()
251251

252252
public function testLazySentinel()
253253
{
254-
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'),
254+
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) {
255+
$this->markTestSkipped('REDIS_SENTINEL_HOSTS env var is not defined.');
256+
}
257+
258+
if (!getenv('MESSENGER_REDIS_SENTINEL_MASTER')) {
259+
$this->markTestSkipped('MESSENGER_REDIS_SENTINEL_MASTER env var is not defined.');
260+
}
261+
262+
$dsn = 'redis:?host['.str_replace(' ', ']&host[', $hosts).']';
263+
264+
$connection = Connection::fromDsn($dsn,
255265
['lazy' => true,
256266
'delete_after_ack' => true,
257267
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
@@ -326,7 +336,7 @@ public function testFromDsnWithMultipleHosts()
326336
$dsn = array_map(fn ($host) => 'redis://'.$host, $hosts);
327337
$dsn = implode(',', $dsn);
328338

329-
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null]));
339+
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, []));
330340
}
331341

332342
public function testJsonError()
@@ -450,7 +460,7 @@ private function getConnectionStream(Connection $connection): string
450460
private function skipIfRedisClusterUnavailable()
451461
{
452462
try {
453-
new \RedisCluster(null, getenv('REDIS_CLUSTER_HOST') ? explode(' ', getenv('REDIS_CLUSTER_HOST')) : []);
463+
new \RedisCluster(null, getenv('REDIS_CLUSTER_HOSTS') ? explode(' ', getenv('REDIS_CLUSTER_HOSTS')) : []);
454464
} catch (\Exception $e) {
455465
self::markTestSkipped($e->getMessage());
456466
}

0 commit comments

Comments
 (0)