Skip to content

Commit ef06874

Browse files
Flush Redis after feature workers stop
1 parent ee0b47a commit ef06874

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

tests/TestCase.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ public static function setUpBeforeClass(): void
2929
}
3030
}
3131

32-
$redisHost = getenv('REDIS_HOST') ?: ($_ENV['REDIS_HOST'] ?? null);
33-
$redisPort = getenv('REDIS_PORT') ?: ($_ENV['REDIS_PORT'] ?? 6379);
34-
if ($redisHost && class_exists(\Redis::class)) {
35-
try {
36-
$redis = new \Redis();
37-
$redis->connect($redisHost, (int) $redisPort);
38-
$redis->flushDB();
39-
} catch (\Throwable $e) {
40-
// Ignore if no redis
41-
}
42-
}
32+
self::flushRedis();
4333

4434
for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) {
4535
self::$workers[$i] = new Process(['php', __DIR__ . '/../vendor/bin/testbench', 'queue:work']);
@@ -53,6 +43,10 @@ public static function tearDownAfterClass(): void
5343
foreach (self::$workers as $worker) {
5444
$worker->stop();
5545
}
46+
47+
self::$workers = [];
48+
49+
self::flushRedis();
5650
}
5751

5852
protected function setUp(): void
@@ -67,17 +61,7 @@ protected function setUp(): void
6761

6862
Cache::flush();
6963

70-
$redisHost = getenv('REDIS_HOST') ?: ($_ENV['REDIS_HOST'] ?? null);
71-
$redisPort = getenv('REDIS_PORT') ?: ($_ENV['REDIS_PORT'] ?? 6379);
72-
if ($redisHost && class_exists(\Redis::class)) {
73-
try {
74-
$redis = new \Redis();
75-
$redis->connect($redisHost, (int) $redisPort);
76-
$redis->flushDB();
77-
} catch (\Throwable $e) {
78-
// Ignore if no redis
79-
}
80-
}
64+
self::flushRedis();
8165
}
8266

8367
protected function defineDatabaseMigrations()
@@ -94,4 +78,19 @@ protected function getPackageProviders($app)
9478
{
9579
return [\Workflow\Providers\WorkflowServiceProvider::class];
9680
}
81+
82+
private static function flushRedis(): void
83+
{
84+
$redisHost = getenv('REDIS_HOST') ?: ($_ENV['REDIS_HOST'] ?? null);
85+
$redisPort = getenv('REDIS_PORT') ?: ($_ENV['REDIS_PORT'] ?? 6379);
86+
if ($redisHost && class_exists(\Redis::class)) {
87+
try {
88+
$redis = new \Redis();
89+
$redis->connect($redisHost, (int) $redisPort);
90+
$redis->flushDB();
91+
} catch (\Throwable $e) {
92+
// Ignore if no redis
93+
}
94+
}
95+
}
9796
}

0 commit comments

Comments
 (0)