8000 Add tests for checkpoint saved in broken loop · symfony/symfony@e6148f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6148f1

Browse files
committed
Add tests for checkpoint saved in broken loop
1 parent d460ba4 commit e6148f1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Symfony/Component/Scheduler/Tests/Generator/MessageGeneratorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1616
use Symfony\Component\Clock\ClockInterface;
17+
use Symfony\Component\Scheduler\Generator\Checkpoint;
1718
use Symfony\Component\Scheduler\Generator\MessageContext;
1819
use Symfony\Component\Scheduler\Generator\MessageGenerator;
1920
use Symfony\Component\Scheduler\RecurringMessage;
@@ -128,6 +129,35 @@ public function testYieldedContext()
128129
$this->assertEquals(self::makeDateTime('22:16:00'), $context->nextTriggerAt);
129130
}
130131

132+
public function testCheckpointSavedInBrokenLoop(): void
133+
{
134+
$now = self::makeDateTime('22:12:00');
135+
136+
$clock = $this->createMock(ClockInterface::class);
137+
$clock->method('now')->willReturnReference($now);
138+
139+
$message = $this->createMessage((object) ['id' => 'message'], '22:13:00', '22:14:00', '22:16:00');
140+
$schedule = (new Schedule())->add($message);
141+
142+
$cache = new ArrayAdapter();
143+
$schedule->stateful($cache);
144+
$checkpoint = new Checkpoint('dummy', cache: $cache);
145+
146+
$scheduler = new MessageGenerator($schedule, 'dummy', clock: $clock, checkpoint: $checkpoint);
147+
148+
// Warmup. The first run is always returns nothing.
149+
$this->assertSame([], iterator_to_array($scheduler->getMessages(), false));
150+
151+
$now = self::makeDateTime('22:13:10');
152+
153+
foreach ($scheduler->getMessages() as $message) {
154+
// Message is handled but loop is broken just after
155+
break;
156+
}
157+
158+
$this->assertEquals(self::makeDateTime('22:13:00'), $checkpoint->time());
159+
}
160+
131161
public static function messagesProvider(): \Generator
132162
{
133163
$first = (object) ['id' => 'first'];

0 commit comments

Comments
 (0)
0