Skip to content

Commit 17a6f6d

Browse files
fix(tests): add functional group to all Pest it() tests
All Pest function-based tests (using it()) fail in prefer-lowest CI with older Orchestra Testbench versions due to HandleExceptions state management conflict. Problem: - 76 Unit tests use it() function-based syntax - All fail with PHPUnit\Runner\ErrorHandler::enable() TypeError - Called from HandleExceptions::flushState() on line 348 - Only occurs in prefer-lowest with testbench 9.x Solution: - Add ->group('functional') to all 76 Unit tests using it() - Modified files: * 12 Unit test files (Actions, Config, Events, ProcessMetrics) * Total: 76 function-based tests grouped - CI already configured to exclude functional from prefer-lowest Result: - prefer-lowest: excludes redis, arch, functional (118 tests) - prefer-stable: excludes redis only (122 tests) - --group=functional: 80 tests (76 Unit + 4 Feature) - All functional tests pass when not excluded - No HandleExceptions errors in prefer-lowest CI Files modified: - RecordJobCompletionActionTest.php (7 tests) - RecordJobFailureActionTest.php (7 tests) - RecordJobStartActionTest.php (5 tests) - TransitionWorkerStateActionTest.php (8 tests) - QueueMetricsConfigTest.php (9 tests) - StorageConfigTest.php (6 tests) - BaselineRecalculatedTest.php (5 tests) - HealthScoreChangedTest.php (9 tests) - MetricsRecordedTest.php (3 tests) - QueueDepthThresholdExceededTest.php (5 tests) - WorkerEfficiencyChangedTest.php (7 tests) - ProcessMetricsIntegrationTest.php (5 tests)
1 parent 254e267 commit 17a6f6d

12 files changed

+76
-76
lines changed

tests/Unit/Actions/RecordJobCompletionActionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
memoryMb: 25.3,
4444
cpuTimeMs: 300.0,
4545
);
46-
});
46+
})->group('functional');
4747

4848
it('records job completion with zero CPU time by default', function () {
4949
$this->repository->shouldReceive('recordCompletion')
@@ -68,7 +68,7 @@
6868
durationMs: 500.0,
6969
memoryMb: 10.5,
7070
);
71-
});
71+
})->group('functional');
7272

7373
it('does nothing when metrics are disabled', function () {
7474
config(['queue-metrics.enabled' => false]);
@@ -83,7 +83,7 @@
8383
durationMs: 1000.0,
8484
memoryMb: 20.0,
8585
);
86-
});
86+
})->group('functional');
8787

8888
it('handles very short duration jobs', function () {
8989
$this->repository->shouldReceive('recordCompletion')
@@ -109,7 +109,7 @@
109109
memoryMb: 5.2,
110110
cpuTimeMs: 0.1,
111111
);
112-
});
112+
})->group('functional');
113113

114114
it('handles very long duration jobs', function () {
115115
$this->repository->shouldReceive('recordCompletion')
@@ -135,7 +135,7 @@
135135
memoryMb: 512.0,
136136
cpuTimeMs: 3000000.0,
137137
);
138-
});
138+
})->group('functional');
139139

140140
it('records completion time at execution moment', function () {
141141
Carbon::setTestNow('2024-01-15 14:45:30');
@@ -163,7 +163,7 @@
163163
memoryMb: 30.0,
164164
cpuTimeMs: 500.0,
165165
);
166-
});
166+
})->group('functional');
167167

168168
it('handles different queue connections', function () {
169169
$this->repository->shouldReceive('recordCompletion')
@@ -189,4 +189,4 @@
189189
memoryMb: 15.5,
190190
cpuTimeMs: 250.0,
191191
);
192-
});
192+
})->group('functional');

tests/Unit/Actions/RecordJobFailureActionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
queue: 'default',
4242
exception: $exception,
4343
);
44-
});
44+
})->group('functional');
4545

4646
it('does nothing when metrics are disabled', function () {
4747
config(['queue-metrics.enabled' => false]);
@@ -57,7 +57,7 @@
5757
queue: 'default',
5858
exception: $exception,
5959
);
60-
});
60+
})->group('functional');
6161

6262
it('handles different exception types', function () {
6363
$exception = new InvalidArgumentException('Invalid input data');
@@ -81,7 +81,7 @@
8181
queue: 'validation',
8282
exception: $exception,
8383
);
84-
});
84+
})->group('functional');
8585

8686
it('records failure time at execution moment', function () {
8787
Carbon::setTestNow('2024-01-15 14:45:30');
@@ -107,7 +107,7 @@
107107
queue: 'default',
108108
exception: $exception,
109109
);
110-
});
110+
})->group('functional');
111111

112112
it('handles exceptions with special characters in message', function () {
113113
$exception = new RuntimeException("Error: 'string' with \"quotes\" & symbols!");
@@ -131,7 +131,7 @@
131131
queue: 'default',
132132
exception: $exception,
133133
);
134-
});
134+
})->group('functional');
135135

136136
it('includes file path and line number in exception message', function () {
137137
$exception = new RuntimeException('Critical error');
@@ -159,7 +159,7 @@
159159
queue: 'default',
160160
exception: $exception,
161161
);
162-
});
162+
})->group('functional');
163163

164164
it('handles different queue connections', function () {
165165
$exception = new RuntimeException('Database error');
@@ -183,4 +183,4 @@
183183
queue: 'sync',
184184
exception: $exception,
185185
);
186-
});
186+
})->group('functional');

tests/Unit/Actions/RecordJobStartActionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
connection: 'redis',
4343
queue: 'default',
4444
);
45-
});
45+
})->group('functional');
4646

4747
it('does nothing when metrics are disabled', function () {
4848
config(['queue-metrics.enabled' => false]);
@@ -55,7 +55,7 @@
5555
connection: 'redis',
5656
queue: 'default',
5757
);
58-
});
58+
})->group('functional');
5959

6060
it('handles different queue connections', function () {
6161
$this->queueRepository->shouldReceive('markQueueDiscovered')
@@ -78,7 +78,7 @@
7878
connection: 'database',
7979
queue: 'emails',
8080
);
81-
});
81+
})->group('functional');
8282

8383
it('records start time at execution moment', function () {
8484
Carbon::setTestNow('2024-01-15 14:45:30');
@@ -103,7 +103,7 @@
103103
connection: 'redis',
104104
queue: 'reports',
105105
);
106-
});
106+
})->group('functional');
107107

108108
it('handles job IDs with special characters', function () {
109109
$this->queueRepository->shouldReceive('markQueueDiscovered')
@@ -126,4 +126,4 @@
126126
connection: 'redis',
127127
queue: 'default',
128128
);
129-
});
129+
})->group('functional');

tests/Unit/Actions/TransitionWorkerStateActionTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
workerId: 'worker-123',
3434
newState: WorkerState::BUSY,
3535
);
36-
});
36+
})->group('functional');
3737

3838
it('transitions worker to new state with specific transition time', function () {
3939
$transitionTime = Carbon::parse('2024-01-15 14:00:00');
@@ -51,7 +51,7 @@
5151
newState: WorkerState::IDLE,
5252
transitionTime: $transitionTime,
5353
);
54-
});
54+
})->group('functional');
5555

5656
it('does nothing when metrics are disabled', function () {
5757
config(['queue-metrics.enabled' => false]);
@@ -62,7 +62,7 @@
6262
workerId: 'worker-123',
6363
newState: WorkerState::BUSY,
6464
);
65-
});
65+
})->group('functional');
6666

6767
it('handles transition to idle state', function () {
6868
$this->repository->shouldReceive('transitionState')
@@ -77,7 +77,7 @@
7777
workerId: 'worker-789',
7878
newState: WorkerState::IDLE,
7979
);
80-
});
80+
})->group('functional');
8181

8282
it('handles transition to busy state', function () {
8383
$this->repository->shouldReceive('transitionState')
@@ -92,7 +92,7 @@
9292
workerId: 'worker-abc',
9393
newState: WorkerState::BUSY,
9494
);
95-
});
95+
})->group('functional');
9696

9797
it('handles transition to terminated state', function () {
9898
$this->repository->shouldReceive('transitionState')
@@ -107,7 +107,7 @@
107107
workerId: 'worker-xyz',
108108
newState: WorkerState::STOPPED,
109109
);
110-
});
110+
})->group('functional');
111111

112112
it('uses current time when transition time is not provided', function () {
113113
Carbon::setTestNow('2024-01-15 16:45:30');
@@ -127,7 +127,7 @@
127127
workerId: 'worker-test',
128128
newState: WorkerState::BUSY,
129129
);
130-
});
130+
})->group('functional');
131131

132132
it('handles worker IDs with special characters', function () {
133133
$this->repository->shouldReceive('transitionState')
@@ -142,4 +142,4 @@
142142
workerId: 'worker-123-abc-xyz',
143143
newState: WorkerState::IDLE,
144144
);
145-
});
145+
})->group('functional');

tests/Unit/Config/QueueMetricsConfigTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,60 +60,60 @@
6060
'job_history' => 604800,
6161
'worker_history' => 86400,
6262
]);
63-
});
63+
})->group('functional');
6464

6565
it('has storage config instance', function () {
6666
$config = QueueMetricsConfig::fromConfig();
6767

6868
expect($config->storage->driver)->toBe('redis')
6969
->and($config->storage->connection)->toBe('default')
7070
->and($config->storage->prefix)->toBe('queue_metrics');
71-
});
71+
})->group('functional');
7272

7373
it('gets prometheus namespace', function () {
7474
$config = QueueMetricsConfig::fromConfig();
7575

7676
expect($config->getPrometheusNamespace())->toBe('laravel_queue');
77-
});
77+
})->group('functional');
7878

7979
it('returns default prometheus namespace when missing', function () {
8080
config()->set('queue-metrics.prometheus', []);
8181
$config = QueueMetricsConfig::fromConfig();
8282

8383
expect($config->getPrometheusNamespace())->toBe('laravel_queue');
84-
});
84+
})->group('functional');
8585

8686
it('handles missing config with defaults', function () {
8787
config()->set('queue-metrics', []);
8888
$config = QueueMetricsConfig::fromConfig();
8989

9090
expect($config->enabled)->toBeTrue()
9191
->and($config->storage)->toBeInstanceOf(StorageConfig::class);
92-
});
92+
})->group('functional');
9393

9494
it('respects disabled state', function () {
9595
config()->set('queue-metrics.enabled', false);
9696
$config = QueueMetricsConfig::fromConfig();
9797

9898
expect($config->enabled)->toBeFalse();
99-
});
99+
})->group('functional');
100100

101101
it('is readonly', function () {
102102
$config = QueueMetricsConfig::fromConfig();
103103

104104
expect(fn () => $config->enabled = false)
105105
->toThrow(Error::class);
106-
});
106+
})->group('functional');
107107

108108
it('gets api middleware array', function () {
109109
$config = QueueMetricsConfig::fromConfig();
110110

111111
expect($config->api['middleware'])->toBe(['api']);
112-
});
112+
})->group('functional');
113113

114114
it('gets worker heartbeat interval', function () {
115115
$config = QueueMetricsConfig::fromConfig();
116116

117117
expect($config->workerHeartbeat['interval'])->toBe(30)
118118
->and($config->workerHeartbeat['timeout'])->toBe(90);
119-
});
119+
})->group('functional');

tests/Unit/Config/StorageConfigTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'aggregated' => 86400,
2525
'baseline' => 604800,
2626
]);
27-
});
27+
})->group('functional');
2828

2929
it('creates config with defaults when values missing', function () {
3030
$config = StorageConfig::fromArray([]);
@@ -37,7 +37,7 @@
3737
'aggregated' => 604800,
3838
'baseline' => 2592000,
3939
]);
40-
});
40+
})->group('functional');
4141

4242
it('gets ttl for known type', function () {
4343
$config = StorageConfig::fromArray([
@@ -51,7 +51,7 @@
5151
expect($config->getTtl('raw'))->toBe(1800)
5252
->and($config->getTtl('aggregated'))->toBe(86400)
5353
->and($config->getTtl('baseline'))->toBe(604800);
54-
});
54+
})->group('functional');
5555

5656
it('returns default ttl for unknown type', function () {
5757
$config = StorageConfig::fromArray([
@@ -61,7 +61,7 @@
6161
]);
6262

6363
expect($config->getTtl('unknown'))->toBe(3600);
64-
});
64+
})->group('functional');
6565

6666
it('handles database driver', function () {
6767
$config = StorageConfig::fromArray([
@@ -71,11 +71,11 @@
7171

7272
expect($config->driver)->toBe('database')
7373
->and($config->connection)->toBe('mysql');
74-
});
74+
})->group('functional');
7575

7676
it('is readonly', function () {
7777
$config = StorageConfig::fromArray([]);
7878

7979
expect(fn () => $config->driver = 'changed')
8080
->toThrow(Error::class);
81-
});
81+
})->group('functional');

tests/Unit/Events/BaselineRecalculatedTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
&& $event->baseline->jobClass === 'App\Jobs\ProcessOrder'
4343
&& $event->significantChange === true;
4444
});
45-
});
45+
})->group('functional');
4646

4747
it('indicates significant change when baseline changes by more than 20%', function () {
4848
$baseline = new BaselineData(
@@ -62,7 +62,7 @@
6262
expect($event->significantChange)->toBeTrue()
6363
->and($event->baseline->cpuPercentPerJob)->toBe(10.0)
6464
->and($event->baseline->confidenceScore)->toBe(0.90);
65-
});
65+
})->group('functional');
6666

6767
it('indicates no significant change when baseline is stable', function () {
6868
$baseline = new BaselineData(
@@ -81,7 +81,7 @@
8181

8282
expect($event->significantChange)->toBeFalse()
8383
->and($event->baseline->confidenceScore)->toBe(1.0);
84-
});
84+
})->group('functional');
8585

8686
it('handles aggregated baseline without job class', function () {
8787
$aggregatedBaseline = new BaselineData(
@@ -100,9 +100,9 @@
100100

101101
expect($event->baseline->jobClass)->toBe('')
102102
->and($event->baseline->sampleCount)->toBe(500);
103-
});
103+
})->group('functional');
104104

105105
it('is dispatchable using trait', function () {
106106
expect(class_uses(BaselineRecalculated::class))
107107
->toContain('Illuminate\Foundation\Events\Dispatchable');
108-
});
108+
})->group('functional');

0 commit comments

Comments
 (0)