|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\Lock\LockFactory; |
|
7
|
|
|
use Symfony\Component\Lock\Store\FlockStore; |
|
8
|
|
|
use Zenstruck\ScheduleBundle\Schedule; |
|
9
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Exception\SkipTask; |
|
10
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Extension\Handler\WithoutOverlappingHandler; |
|
11
|
|
|
use Zenstruck\ScheduleBundle\Schedule\ScheduleRunContext; |
|
12
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Task\TaskRunContext; |
|
13
|
|
|
use Zenstruck\ScheduleBundle\Tests\Fixture\MockLogger; |
|
14
|
|
|
use Zenstruck\ScheduleBundle\Tests\Fixture\MockScheduleBuilder; |
|
15
|
|
|
use Zenstruck\ScheduleBundle\Tests\Fixture\MockTask; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Kevin Bond <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
final class WithoutOverlappingExtensionTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @test |
|
24
|
|
|
*/ |
|
25
|
|
|
public function task_cannot_be_run_if_locked() |
|
26
|
|
|
{ |
|
27
|
|
|
$handler = new WithoutOverlappingHandler(); |
|
28
|
|
|
$runContext1 = new TaskRunContext(new ScheduleRunContext(new Schedule()), MockTask::success('task')->withoutOverlapping()); |
|
29
|
|
|
$runContext2 = new TaskRunContext(new ScheduleRunContext(new Schedule()), MockTask::success('task')->withoutOverlapping()); |
|
30
|
|
|
|
|
31
|
|
|
$handler->filterTask($runContext1, $runContext1->getTask()->getExtensions()[0]); |
|
32
|
|
|
|
|
33
|
|
|
$this->expectException(SkipTask::class); |
|
34
|
|
|
$this->expectExceptionMessage('Task running in another process.'); |
|
35
|
|
|
|
|
36
|
|
|
$handler->filterTask($runContext2, $runContext2->getTask()->getExtensions()[0]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @test |
|
41
|
|
|
*/ |
|
42
|
|
|
public function lock_is_released_after_task() |
|
43
|
|
|
{ |
|
44
|
|
|
$logger = new MockLogger(); |
|
45
|
|
|
$lockFactory = new LockFactory(new FlockStore()); |
|
46
|
|
|
$lockFactory->setLogger($logger); |
|
47
|
|
|
|
|
48
|
|
|
(new MockScheduleBuilder()) |
|
49
|
|
|
->addHandler(new WithoutOverlappingHandler($lockFactory)) |
|
50
|
|
|
->addTask((new MockTask())->withoutOverlapping()) |
|
51
|
|
|
->run() |
|
52
|
|
|
; |
|
53
|
|
|
|
|
54
|
|
|
$this->assertTrue($logger->hasMessageThatContains('Successfully acquired')); |
|
55
|
|
|
$this->assertTrue($logger->hasMessageThatContains('Expiration defined')); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths