Skip to content

Commit e5082f9

Browse files
Normalize probe replay now context
1 parent f576cc4 commit e5082f9

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/Exception.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Foundation\Bus\Dispatchable;
1111
use Illuminate\Queue\InteractsWithQueue;
1212
use Illuminate\Queue\SerializesModels;
13+
use Illuminate\Support\Carbon;
1314
use Illuminate\Support\Facades\Cache;
1415
use ReflectionClass;
1516
use Throwable;
@@ -138,7 +139,7 @@ private function probeReplayDecision(): string
138139
WorkflowStub::setContext([
139140
'storedWorkflow' => $tentativeWorkflow,
140141
'index' => 0,
141-
'now' => $this->now,
142+
'now' => Carbon::parse($this->now),
142143
'replaying' => true,
143144
'probing' => true,
144145
'probeIndex' => $this->index,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Fixtures;
6+
7+
use Illuminate\Support\Carbon;
8+
use Workflow\SignalMethod;
9+
use Workflow\Workflow;
10+
use Workflow\WorkflowStub;
11+
12+
final class TestProbeNowSignalWorkflow extends Workflow
13+
{
14+
public static bool $signalSawCarbonNow = false;
15+
16+
#[SignalMethod]
17+
public function recordNowType(): void
18+
{
19+
self::$signalSawCarbonNow = WorkflowStub::now() instanceof Carbon;
20+
}
21+
22+
public function execute()
23+
{
24+
if (false) {
25+
yield;
26+
}
27+
28+
return 'ok';
29+
}
30+
}

tests/Unit/ExceptionTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Tests\Fixtures\TestActivity;
1616
use Tests\Fixtures\TestProbeBackToBackWorkflow;
1717
use Tests\Fixtures\TestProbeChildFailureWorkflow;
18+
use Tests\Fixtures\TestProbeNowSignalWorkflow;
1819
use Tests\Fixtures\TestProbeParallelChildWorkflow;
1920
use Tests\Fixtures\TestProbeRetryActivity;
2021
use Tests\Fixtures\TestSagaActivity;
@@ -237,6 +238,35 @@ public function testProbeReplayShortCircuitsWhenWorkflowClassAutoloadThrows(): v
237238
}
238239
}
239240

241+
public function testProbeReplayUsesCarbonNowBeforeWorkflowHandleResetsContext(): void
242+
{
243+
TestProbeNowSignalWorkflow::$signalSawCarbonNow = false;
244+
245+
$workflow = WorkflowStub::load(WorkflowStub::make(TestProbeNowSignalWorkflow::class)->id());
246+
$storedWorkflow = StoredWorkflow::findOrFail($workflow->id());
247+
$storedWorkflow->update([
248+
'arguments' => Serializer::serialize([]),
249+
'status' => WorkflowRunningStatus::$name,
250+
]);
251+
$storedWorkflow->signals()
252+
->create([
253+
'method' => 'recordNowType',
254+
'arguments' => Serializer::serialize([]),
255+
]);
256+
257+
$exception = new Exception(0, now()->toDateTimeString(), $storedWorkflow, [
258+
'class' => BaseException::class,
259+
'message' => 'probe now type',
260+
'code' => 0,
261+
], connection: 'redis', queue: 'default');
262+
263+
$method = new ReflectionMethod(Exception::class, 'probeReplayDecision');
264+
$method->setAccessible(true);
265+
$method->invoke($exception);
266+
267+
$this->assertTrue(TestProbeNowSignalWorkflow::$signalSawCarbonNow);
268+
}
269+
240270
public function testSkipsWriteWhenProbeDoesNotReachCandidateException(): void
241271
{
242272
$workflow = WorkflowStub::load(WorkflowStub::make(TestProbeParallelChildWorkflow::class)->id());

0 commit comments

Comments
 (0)