-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathErrorHandlingTest.php
More file actions
136 lines (118 loc) · 4.39 KB
/
Copy pathErrorHandlingTest.php
File metadata and controls
136 lines (118 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Tests\Jobs;
use Illuminate\Support\Facades\Queue;
use Mockery;
use ProcessMaker\Jobs\ErrorHandling;
use ProcessMaker\Jobs\RunScriptTask;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\Script;
use Tests\TestCase;
class ErrorHandlingTest extends TestCase
{
private function runAssertions($settings)
{
Queue::fake();
extract($settings);
$errorHandling = ['timeout' => $bpmnTimeout, 'retry_attempts' => $bpmnRetryAttempts, 'retry_wait_time' => $bpmnRetryWaitTime];
$element = Mockery::mock();
$element->shouldReceive('getProperty')->andReturn(json_encode($errorHandling));
$script = Script::factory()->create(['timeout' => $modelTimeout, 'retry_attempts' => $modelRetryAttempts, 'retry_wait_time' => $modelRetryWaitTime]);
$process = Process::factory()->create();
$processRequest = ProcessRequest::factory()->create([
'process_id' => $process->id,
]);
$token = ProcessRequestToken::factory()->create([
'process_request_id' => $processRequest->id,
]);
$job = new RunScriptTask($process, $processRequest, $token, [], $attempt);
$errorHandling = new ErrorHandling($element, $token);
$errorHandling->setDefaultsFromScript($script->getLatestVersion());
$this->assertEquals($expectedTimeout, $errorHandling->timeout());
$errorHandling->handleRetries($job, new \RuntimeException('error'));
if ($expectedNextAttempt !== false) {
Queue::assertPushed(RunScriptTask::class, function ($job) use ($expectedNextAttempt, $expectedWaitTime) {
return $job->attemptNum === $expectedNextAttempt &&
$job->delay === $expectedWaitTime;
});
} else {
Queue::assertNotPushed(RunScriptTask::class);
}
}
public function testRetry()
{
$this->runAssertions([
'attempt' => 3,
'expectedTimeout' => 15,
'expectedNextAttempt' => 4, // retry the job
'expectedWaitTime' => 5,
'modelTimeout' => 8,
'modelRetryAttempts' => 2,
'modelRetryWaitTime' => 6,
'bpmnTimeout' => 15,
'bpmnRetryAttempts' => 3,
'bpmnRetryWaitTime' => 5,
]);
}
public function testRetryUseModelSettings()
{
$this->runAssertions([
'attempt' => 3,
'expectedTimeout' => 15,
'expectedNextAttempt' => 4, // retry the job
'expectedWaitTime' => 5,
'modelTimeout' => 8,
'modelRetryAttempts' => 99,
'modelRetryWaitTime' => 6,
'bpmnTimeout' => 15,
'bpmnRetryAttempts' => '', // use modelRetryAttempts
'bpmnRetryWaitTime' => 5,
]);
}
public function testDoNotRetry()
{
$this->runAssertions([
'attempt' => 4,
'expectedTimeout' => 15,
'expectedNextAttempt' => false, // do not retry the job because attempt is 4 and bpmnRetryAttempts is 3
'expectedWaitTime' => 5,
'modelTimeout' => 8,
'modelRetryAttempts' => 2,
'modelRetryWaitTime' => 6,
'bpmnTimeout' => 15,
'bpmnRetryAttempts' => 3,
'bpmnRetryWaitTime' => 5,
]);
}
public function testRetryWaitFromModel()
{
$this->runAssertions([
'attempt' => 3,
'expectedTimeout' => 15,
'expectedNextAttempt' => 4,
'expectedWaitTime' => 6, // use modelRetryWaitTime because bpmnWaitTime is empty
'modelTimeout' => 8,
'modelRetryAttempts' => 2,
'modelRetryWaitTime' => 6,
'bpmnTimeout' => 15,
'bpmnRetryAttempts' => 3,
'bpmnRetryWaitTime' => '',
]);
}
public function testTimeoutFromModel()
{
$this->runAssertions([
'attempt' => 3,
'expectedTimeout' => 8, // use modelTimeout because bpmnTimeout is empty
'expectedNextAttempt' => 4,
'expectedWaitTime' => 5,
'modelTimeout' => 8,
'modelRetryAttempts' => 2,
'modelRetryWaitTime' => 6,
'bpmnTimeout' => '',
'bpmnRetryAttempts' => 3,
'bpmnRetryWaitTime' => 5,
]);
}
}