|
7 | 7 | use Exception as BaseException; |
8 | 8 | use InvalidArgumentException; |
9 | 9 | use RuntimeException; |
| 10 | +use Tests\Fixtures\TestActivity; |
10 | 11 | use Tests\Fixtures\TestProbeBackToBackWorkflow; |
11 | 12 | use Tests\Fixtures\TestProbeChildFailureWorkflow; |
12 | 13 | use Tests\Fixtures\TestProbeParallelChildWorkflow; |
13 | 14 | use Tests\Fixtures\TestProbeRetryActivity; |
| 15 | +use Tests\Fixtures\TestSagaActivity; |
| 16 | +use Tests\Fixtures\TestSagaParallelActivityWorkflow; |
14 | 17 | use Tests\Fixtures\TestWorkflow; |
15 | 18 | use Tests\TestCase; |
16 | 19 | use Workflow\Exception; |
@@ -115,4 +118,45 @@ public function testPersistsWriteWhenProbeReachesCandidateException(): void |
115 | 118 |
|
116 | 119 | $this->assertTrue($storedWorkflow->fresh()->hasLogByIndex(1)); |
117 | 120 | } |
| 121 | + |
| 122 | + public function testSkipsWriteWhenProbeReachesDifferentActivityClassAtSameIndex(): void |
| 123 | + { |
| 124 | + $workflow = WorkflowStub::load(WorkflowStub::make(TestSagaParallelActivityWorkflow::class)->id()); |
| 125 | + $storedWorkflow = StoredWorkflow::findOrFail($workflow->id()); |
| 126 | + $storedWorkflow->update([ |
| 127 | + 'arguments' => Serializer::serialize([]), |
| 128 | + 'status' => WorkflowRunningStatus::$name, |
| 129 | + ]); |
| 130 | + |
| 131 | + $storedWorkflow->logs() |
| 132 | + ->create([ |
| 133 | + 'index' => 0, |
| 134 | + 'now' => now() |
| 135 | + ->toDateTimeString(), |
| 136 | + 'class' => TestActivity::class, |
| 137 | + 'result' => Serializer::serialize('step complete'), |
| 138 | + ]); |
| 139 | + |
| 140 | + $storedWorkflow->logs() |
| 141 | + ->create([ |
| 142 | + 'index' => 1, |
| 143 | + 'now' => now() |
| 144 | + ->toDateTimeString(), |
| 145 | + 'class' => Exception::class, |
| 146 | + 'result' => Serializer::serialize([ |
| 147 | + 'class' => RuntimeException::class, |
| 148 | + 'message' => 'parallel failure', |
| 149 | + 'code' => 0, |
| 150 | + ]), |
| 151 | + ]); |
| 152 | + |
| 153 | + $exception = new Exception(2, now()->toDateTimeString(), $storedWorkflow, [ |
| 154 | + 'class' => RuntimeException::class, |
| 155 | + 'message' => 'another parallel failure', |
| 156 | + 'code' => 0, |
| 157 | + ], sourceClass: TestSagaActivity::class); |
| 158 | + $exception->handle(); |
| 159 | + |
| 160 | + $this->assertFalse($storedWorkflow->fresh()->hasLogByIndex(2)); |
| 161 | + } |
118 | 162 | } |
0 commit comments