|
18 | 18 | use Berlioz\QueueManager\Worker; |
19 | 19 | use Berlioz\QueueManager\WorkerExit; |
20 | 20 | use Berlioz\QueueManager\WorkerOptions; |
| 21 | +use PHPUnit\Framework\Attributes\DataProvider; |
21 | 22 | use PHPUnit\Framework\TestCase; |
22 | 23 | use Psr\Log\LoggerInterface; |
23 | 24 | use ReflectionClass; |
@@ -164,4 +165,60 @@ public function testRunExitsWhenKillFileExists() |
164 | 165 |
|
165 | 166 | unlink($killFile); // Cleanup |
166 | 167 | } |
| 168 | + |
| 169 | + public static function provideJobAndOptionsForDelay() |
| 170 | + { |
| 171 | + return [ |
| 172 | + [ |
| 173 | + 'jobAttempts' => 1, |
| 174 | + 'backoffTime' => 30, |
| 175 | + 'backoffMultiplier' => 2, |
| 176 | + 'exceptedDelay' => 30, |
| 177 | + ], |
| 178 | + [ |
| 179 | + 'jobAttempts' => 2, |
| 180 | + 'backoffTime' => 30, |
| 181 | + 'backoffMultiplier' => 2, |
| 182 | + 'exceptedDelay' => 60, |
| 183 | + ], |
| 184 | + [ |
| 185 | + 'jobAttempts' => 3, |
| 186 | + 'backoffTime' => 30, |
| 187 | + 'backoffMultiplier' => 2, |
| 188 | + 'exceptedDelay' => 120, |
| 189 | + ], |
| 190 | + [ |
| 191 | + 'jobAttempts' => 4, |
| 192 | + 'backoffTime' => 30, |
| 193 | + 'backoffMultiplier' => 2, |
| 194 | + 'exceptedDelay' => 240, |
| 195 | + ], |
| 196 | + [ |
| 197 | + 'jobAttempts' => 3, |
| 198 | + 'backoffTime' => 30, |
| 199 | + 'backoffMultiplier' => 1, |
| 200 | + 'exceptedDelay' => 30, |
| 201 | + ], |
| 202 | + [ |
| 203 | + 'jobAttempts' => 3, |
| 204 | + 'backoffTime' => 1, |
| 205 | + 'backoffMultiplier' => 2, |
| 206 | + 'exceptedDelay' => 4, |
| 207 | + ], |
| 208 | + ]; |
| 209 | + } |
| 210 | + |
| 211 | + #[DataProvider('provideJobAndOptionsForDelay')] |
| 212 | + public function testNextDelayAfterFailure( |
| 213 | + int $jobAttempts, |
| 214 | + int $backoffTime, |
| 215 | + int $backoffMultiplier, |
| 216 | + int $exceptedDelay |
| 217 | + ) { |
| 218 | + $options = new WorkerOptions(backoffTime: $backoffTime, backoffMultiplier: $backoffMultiplier); |
| 219 | + $jobMock = $this->createMock(JobInterface::class); |
| 220 | + $jobMock->method('getAttempts')->willReturn($jobAttempts); |
| 221 | + |
| 222 | + $this->assertEquals($exceptedDelay, $this->worker->nextDelayAfterFailure($jobMock, $options)); |
| 223 | + } |
167 | 224 | } |
0 commit comments