|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
16 | 16 | use Symfony\Component\Clock\ClockInterface;
|
| 17 | +use Symfony\Component\Clock\MockClock; |
| 18 | +use Symfony\Component\Scheduler\Generator\Checkpoint; |
17 | 19 | use Symfony\Component\Scheduler\Generator\MessageContext;
|
18 | 20 | use Symfony\Component\Scheduler\Generator\MessageGenerator;
|
19 | 21 | use Symfony\Component\Scheduler\RecurringMessage;
|
@@ -128,6 +130,32 @@ public function testYieldedContext()
|
128 | 130 | $this->assertEquals(self::makeDateTime('22:16:00'), $context->nextTriggerAt);
|
129 | 131 | }
|
130 | 132 |
|
| 133 | + public function testCheckpointSavedInBrokenLoop() |
| 134 | + { |
| 135 | + $clock = new MockClock(self::makeDateTime('22:12:00')); |
| 136 | + |
| 137 | + $message = $this->createMessage((object) ['id' => 'message'], '22:13:00', '22:14:00', '22:16:00'); |
| 138 | + $schedule = (new Schedule())->add($message); |
| 139 | + |
| 140 | + $cache = new ArrayAdapter(); |
| 141 | + $schedule->stateful($cache); |
| 142 | + $checkpoint = new Checkpoint('dummy', cache: $cache); |
| 143 | + |
| 144 | + $scheduler = new MessageGenerator($schedule, 'dummy', clock: $clock, checkpoint: $checkpoint); |
| 145 | + |
| 146 | + // Warmup. The first run is always returns nothing. |
| 147 | + $this->assertSame([], iterator_to_array($scheduler->getMessages(), false)); |
| 148 | + |
| 149 | + $clock->sleep(60 + 10); // 22:13:10 |
| 150 | + |
| 151 | + foreach ($scheduler->getMessages() as $message) { |
| 152 | + // Message is handled but loop is broken just after |
| 153 | + break; |
| 154 | + } |
| 155 | + |
| 156 | + $this->assertEquals(self::makeDateTime('22:13:00'), $checkpoint->time()); |
| 157 | + } |
| 158 | + |
131 | 159 | public static function messagesProvider(): \Generator
|
132 | 160 | {
|
133 | 161 | $first = (object) ['id' => 'first'];
|
|
0 commit comments