Skip to content

Commit ca88219

Browse files
authored
[12.x] Queue tests for Redis Cluster missing QUEUE_CONNECTION (#57641)
* [12.x] Queue tests for Redis Cluster missing QUEUE_CONNECTION * [12.x] setUpRedis in QueueTestCase * [12.x] Jobs order asserts for non-sync queues in JobChainingTest * [12.x] Check Redis Cluster is ready
1 parent 8583094 commit ca88219

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.github/workflows/queues.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,25 @@ jobs:
169169
redis-server --daemonize yes --port 7002 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7002.conf
170170
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0 --cluster-yes
171171
172+
- name: Check Redis Cluster is ready
173+
uses: nick-fields/retry@v3
174+
with:
175+
timeout_seconds: 5
176+
max_attempts: 5
177+
retry_wait_seconds: 5
178+
retry_on: error
179+
command: |
180+
redis-cli -c -h 127.0.0.1 -p 7000 cluster info | grep "cluster_state:ok"
181+
redis-cli -c -h 127.0.0.1 -p 7001 cluster info | grep "cluster_state:ok"
182+
redis-cli -c -h 127.0.0.1 -p 7002 cluster info | grep "cluster_state:ok"
183+
172184
- name: Execute tests
173185
run: vendor/bin/phpunit tests/Integration/Queue
174186
env:
175187
REDIS_CLIENT: ${{ matrix.client }}
176188
REDIS_CLUSTER_HOSTS_AND_PORTS: 127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002
177189
REDIS_QUEUE: '{default}'
190+
QUEUE_CONNECTION: redis
178191

179192
beanstalkd:
180193
runs-on: ubuntu-24.04

tests/Integration/Queue/JobChainingTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public function testDynamicBatchCanBeAddedToChain()
416416
$this->assertEquals(
417417
['c1', 'c2', 'b1', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results
418418
);
419+
} else {
420+
$this->assertEquals(
421+
['c1', 'c2', 'b1', 'b2', 'b3', 'b4', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'c3'], JobRunRecorder::$results
422+
);
419423
}
420424

421425
$this->assertCount(11, JobRunRecorder::$results);
@@ -445,6 +449,10 @@ public function testChainBatchChain()
445449
$this->assertEquals(
446450
['c1', 'c2', 'bc1', 'bc2', 'b1', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results
447451
);
452+
} else {
453+
$this->assertEquals(
454+
['c1', 'c2', 'bc1', 'b1', 'b2', 'b3', 'b4', 'bc2', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'c3'], JobRunRecorder::$results
455+
);
448456
}
449457

450458
$this->assertCount(13, JobRunRecorder::$results);
@@ -478,6 +486,10 @@ public function testChainBatchChainBatch()
478486
$this->assertEquals(
479487
['c1', 'c2', 'bc1', 'bc2', 'bb1', 'bb2', 'b1', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results
480488
);
489+
} else {
490+
$this->assertEquals(
491+
['c1', 'c2', 'bc1', 'b1', 'b2', 'b3', 'b4', 'bc2', 'b2-0', 'b2-1', 'b2-2', 'b2-3', 'bb1', 'bb2', 'c3'], JobRunRecorder::$results
492+
);
481493
}
482494

483495
$this->assertCount(15, JobRunRecorder::$results);

tests/Integration/Queue/QueueTestCase.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace Illuminate\Tests\Integration\Queue;
44

5+
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
56
use Illuminate\Foundation\Testing\DatabaseMigrations;
67
use Orchestra\Testbench\TestCase;
78

89
abstract class QueueTestCase extends TestCase
910
{
10-
use DatabaseMigrations;
11+
use DatabaseMigrations, InteractsWithRedis;
1112

1213
/**
1314
* The current database driver.
@@ -27,6 +28,24 @@ protected function defineEnvironment($app)
2728
$this->driver = $app['config']->get('queue.default', 'sync');
2829
}
2930

31+
#[\Override]
32+
protected function setUp(): void
33+
{
34+
$this->afterApplicationCreated(function () {
35+
if ($this->getQueueDriver() === 'redis') {
36+
$this->setUpRedis();
37+
}
38+
});
39+
40+
$this->beforeApplicationDestroyed(function () {
41+
if ($this->getQueueDriver() === 'redis') {
42+
$this->tearDownRedis();
43+
}
44+
});
45+
46+
parent::setUp();
47+
}
48+
3049
/**
3150
* Run queue worker command.
3251
*

0 commit comments

Comments
 (0)