Línea 298... |
Línea 298... |
298 |
$this->assertCount(0, $running);
|
298 |
$this->assertCount(0, $running);
|
Línea 299... |
Línea 299... |
299 |
|
299 |
|
300 |
$scheduledtask1 = manager::get_scheduled_task(scheduled_test_task::class);
|
300 |
$scheduledtask1 = manager::get_scheduled_task(scheduled_test_task::class);
|
301 |
self::assertGreaterThan($next1->get_fail_delay(), $scheduledtask1->get_fail_delay());
|
301 |
self::assertGreaterThan($next1->get_fail_delay(), $scheduledtask1->get_fail_delay());
|
- |
|
302 |
}
|
- |
|
303 |
|
- |
|
304 |
public function test_get_next_adhoc_task_will_respect_failed_tasks(): void {
|
- |
|
305 |
// Create three tasks, one is burned on the first get_next_adhoc_task() call to build up the cache,
|
- |
|
306 |
// the second will be set to failed and the third is required to make the "uniquetasksinqueue" query
|
- |
|
307 |
// within the get_next_adhoc_task() function not returning a different count of remaining unique tasks.
|
- |
|
308 |
manager::queue_adhoc_task(new adhoc_test_task());
|
- |
|
309 |
manager::queue_adhoc_task(new adhoc_test_task());
|
- |
|
310 |
manager::queue_adhoc_task(new adhoc_test_task());
|
- |
|
311 |
$timestart = time();
|
- |
|
312 |
|
- |
|
313 |
$candidates = manager::get_candidate_adhoc_tasks($timestart, 4, null);
|
- |
|
314 |
$this->assertEquals(count($candidates), 3);
|
- |
|
315 |
$task1 = manager::adhoc_task_from_record(array_shift($candidates));
|
- |
|
316 |
$task2 = manager::adhoc_task_from_record(array_shift($candidates));
|
- |
|
317 |
$task3 = manager::adhoc_task_from_record(array_shift($candidates));
|
- |
|
318 |
|
- |
|
319 |
// Build up the cache by getting the first task.
|
- |
|
320 |
$task = manager::get_next_adhoc_task($timestart);
|
- |
|
321 |
// Release the lock by completing the task to avoid "A lock was created but not released" error if the assertion fails.
|
- |
|
322 |
manager::adhoc_task_complete($task);
|
- |
|
323 |
$this->assertEquals($task->get_id(), $task1->get_id());
|
- |
|
324 |
|
- |
|
325 |
// Make $task2 failed...
|
- |
|
326 |
try {
|
- |
|
327 |
// Expecting "Error: Call to a member function release() on null" as the task was not locked before.
|
- |
|
328 |
manager::adhoc_task_failed($task2);
|
- |
|
329 |
} catch (\Throwable $t) {
|
- |
|
330 |
// Ignoring "Call to a member function release() on null" and throw anything else.
|
- |
|
331 |
if ($t->getMessage() != "Call to a member function release() on null") {
|
- |
|
332 |
throw $t;
|
- |
|
333 |
}
|
- |
|
334 |
}
|
- |
|
335 |
$task = manager::get_next_adhoc_task($timestart);
|
- |
|
336 |
// Release the lock by completing the task to avoid "A lock was created but not released" error if the assertion fails.
|
- |
|
337 |
manager::adhoc_task_complete($task);
|
- |
|
338 |
// Task $task2 should not be returned because it has failed meanwhile and
|
- |
|
339 |
// therefore has its nextruntime in the future...
|
- |
|
340 |
$this->assertNotEquals($task->get_id(), $task2->get_id());
|
- |
|
341 |
|
- |
|
342 |
// Just to make sure check that the complete queue is as expected.
|
- |
|
343 |
$this->assertEquals($task->get_id(), $task3->get_id());
|
- |
|
344 |
// Now the queue should be empty...
|
- |
|
345 |
$task = manager::get_next_adhoc_task($timestart);
|
- |
|
346 |
$this->assertNull($task);
|
- |
|
347 |
|
- |
|
348 |
$this->resetAfterTest();
|
302 |
}
|
349 |
}
|