Skip to content

Commit f68af6d

Browse files
fix: separate Redis integration tests from unit tests
Addresses CI failures by properly segregating Redis-dependent tests. Changes: 1. **Workflow separation**: - test job: Excludes redis group (runs without Redis) - test-with-redis job: Only runs redis group tests - Fixes "redis-cli: command not found" by using PHP Redis extension 2. **Test grouping**: - Performance tests: Added 'redis' group (require Redis) - EventListenersTest: Added @group redis annotation - Unit tests: Run without Redis via config disable 3. **Redis connection check**: - Replaced bash redis-cli with PHP Redis extension check - More reliable and consistent with test environment Expected results: - test job: ~119 tests (unit tests only) - test-with-redis job: ~8 tests (integration/performance) - ProcessMetricsIntegrationTest errors unrelated to Redis
1 parent b4effa1 commit f68af6d

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.github/workflows/run-tests.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: composer show -D
5858

5959
- name: Execute tests
60-
run: vendor/bin/pest --ci
60+
run: vendor/bin/pest --ci --exclude-group=redis
6161

6262
test-with-redis:
6363
runs-on: ubuntu-latest
@@ -118,10 +118,26 @@ jobs:
118118
119119
- name: Wait for Redis
120120
run: |
121-
timeout 30 bash -c 'until redis-cli -h 127.0.0.1 -p 6379 ping; do sleep 1; done'
121+
php -r "
122+
\$redis = new Redis();
123+
\$start = time();
124+
while (time() - \$start < 30) {
125+
try {
126+
if (\$redis->connect('127.0.0.1', 6379, 1)) {
127+
echo 'Redis is ready\n';
128+
exit(0);
129+
}
130+
} catch (Exception \$e) {
131+
sleep(1);
132+
}
133+
}
134+
echo 'Timeout waiting for Redis\n';
135+
exit(1);
136+
"
122137
123138
- name: Execute integration tests
124-
run: vendor/bin/pest --ci
139+
run: vendor/bin/pest --ci --group=redis
125140
env:
126141
REDIS_HOST: 127.0.0.1
127142
REDIS_PORT: 6379
143+
REDIS_AVAILABLE: true

tests/Feature/EventListenersTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use PHPeek\LaravelQueueMetrics\Repositories\Contracts\JobMetricsRepository;
1212
use PHPeek\LaravelQueueMetrics\Tests\Feature\Support\TestJob;
1313

14+
/**
15+
* @group redis
16+
*/
1417
final class EventListenersTest extends TestCase
1518
{
1619
use RefreshDatabase;

tests/Performance/BaselineCalculationBenchmarkTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// Assert: Should complete within 5 seconds even with 1000 samples
2525
expect($duration)->toBeLessThan(5.0);
26-
})->group('performance', 'slow');
26+
})->group('performance', 'slow', 'redis');
2727

2828
test('batch baseline fetching is faster than sequential', function () {
2929
$baselineRepository = app(BaselineRepository::class);
@@ -51,7 +51,7 @@
5151
// Assert: Batch should not be significantly slower (allow 2x tolerance for overhead)
5252
// With empty data, batch operations may have pipeline overhead
5353
expect($batchDuration)->toBeLessThan($sequentialDuration * 2);
54-
})->group('performance', 'slow');
54+
})->group('performance', 'slow', 'redis');
5555

5656
test('key scanning performance is acceptable for large datasets', function () {
5757
$keyScanner = app(\PHPeek\LaravelQueueMetrics\Services\RedisKeyScannerService::class);
@@ -75,7 +75,7 @@
7575

7676
// Assert: Scanning should complete within 2 seconds
7777
expect($duration)->toBeLessThan(2.0);
78-
})->group('performance');
78+
})->group('performance', 'redis');
7979

8080
test('overview query aggregation completes within acceptable time', function () {
8181
$overviewService = app(\PHPeek\LaravelQueueMetrics\Services\OverviewQueryService::class);
@@ -91,7 +91,7 @@
9191
expect($duration)->toBeLessThan(3.0);
9292
expect($overview)->toBeArray();
9393
expect($overview)->toHaveKeys(['queues', 'jobs', 'servers', 'workers', 'baselines', 'metadata']);
94-
})->group('performance', 'slow');
94+
})->group('performance', 'slow', 'redis');
9595

9696
test('redis transaction is faster or same speed as pipeline for critical mutations', function () {
9797
$jobMetricsRepository = app(\PHPeek\LaravelQueueMetrics\Repositories\Contracts\JobMetricsRepository::class);
@@ -127,7 +127,7 @@
127127

128128
// Assert: 10 transactions should complete within 1 second
129129
expect($duration)->toBeLessThan(1.0);
130-
})->group('performance');
130+
})->group('performance', 'redis');
131131

132132
test('memory usage stays reasonable during large batch operations', function () {
133133
$overviewService = app(\PHPeek\LaravelQueueMetrics\Services\OverviewQueryService::class);
@@ -141,4 +141,4 @@
141141

142142
// Assert: Memory increase should be less than 50MB for overview query
143143
expect($memoryIncrease)->toBeLessThan(50);
144-
})->group('performance');
144+
})->group('performance', 'redis');

0 commit comments

Comments
 (0)