FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
workflow-engine-core/tests/Unit/ExecutorRetryTest.php at main · solutionforest/workflow-engine-core · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
solutionforest
/
workflow-engine-core
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
3
Star
9
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
workflow-engine-core
/
tests
/
Unit
/
ExecutorRetryTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (92 loc) · 3.74 KB
Breadcrumbs
workflow-engine-core
/
tests
/
Unit
/
ExecutorRetryTest.php
Copy path
File metadata and controls
116 lines (92 loc) · 3.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
use
SolutionForest
\
WorkflowEngine
\
Actions
\
BaseAction
;
use
SolutionForest
\
WorkflowEngine
\
Core
\
ActionResult
;
use
SolutionForest
\
WorkflowEngine
\
Core
\
WorkflowBuilder
;
use
SolutionForest
\
WorkflowEngine
\
Core
\
WorkflowContext
;
use
SolutionForest
\
WorkflowEngine
\
Core
\
WorkflowEngine
;
use
SolutionForest
\
WorkflowEngine
\
Exceptions
\
StepExecutionException
;
use
SolutionForest
\
WorkflowEngine
\
Tests
\
Support
\
InMemoryStorage
;
use
SolutionForest
\
WorkflowEngine
\
Tests
\
Support
\
SpyEventDispatcher
;
// A test action that fails N times then succeeds
class
FailNTimesAction
extends
BaseAction
{
private
static
int
$
callCount
=
0
;
public
static
function
reset
():
void
{
self
::
$
callCount
=
0
;
}
protected
function
doExecute
(
WorkflowContext
$
context
):
ActionResult
{
self
::
$
callCount
++;
$
failCount
=
$
this
->
getConfig
(
'
fail_count
'
,
0
);
if
(
self
::
$
callCount
<=
$
failCount
) {
throw
new
RuntimeException
(
'
Intentional failure #
'
.
self
::
$
callCount
);
}
return
ActionResult::
success
([
'
attempts
'
=>
self
::
$
callCount
]);
}
public
function
getName
():
string
{
return
'
Fail N Times
'
;
}
public
function
getDescription
():
string
{
return
'
Test action that fails a configurable number of times
'
;
}
}
// A test action that always fails
class
AlwaysFailAction
extends
BaseAction
{
protected
function
doExecute
(
WorkflowContext
$
context
):
ActionResult
{
throw
new
RuntimeException
(
'
Always fails
'
);
}
public
function
getName
():
string
{
return
'
Always Fail
'
;
}
public
function
getDescription
():
string
{
return
'
Test action that always fails
'
;
}
}
describe
(
'
Executor Retry Logic
'
,
function
() {
beforeEach
(
function
() {
FailNTimesAction::
reset
();
});
test
(
'
retries and succeeds after transient failure
'
,
function
() {
$
storage
=
new
InMemoryStorage
;
$
spy
=
new
SpyEventDispatcher
;
$
engine
=
new
WorkflowEngine
(
$
storage
,
$
spy
);
$
definition
= WorkflowBuilder::
create
(
'
retry-test
'
)
->
addStep
(
'
flaky_step
'
, FailNTimesAction::class, [
'
fail_count
'
=>
2
], retryAttempts:
3
)
->
build
();
$
id
=
$
engine
->
start
(
'
retry-success
'
,
$
definition
->
toArray
(), []);
$
instance
=
$
engine
->
getInstance
(
$
id
);
expect
(
$
instance
->
getState
()->
value
)->
toBe
(
'
completed
'
);
// Should have dispatched StepRetried events
$
retryEvents
=
array_filter
(
$
spy
->
dispatched
,
fn
(
$
e
) =>
str_contains
(
get_class
(
$
e
),
'
StepRetried
'
));
expect
(
count
(
$
retryEvents
))->
toBe
(
2
);
// Failed twice before succeeding
});
test
(
'
fails after exhausting all retry attempts
'
,
function
() {
$
storage
=
new
InMemoryStorage
;
$
spy
=
new
SpyEventDispatcher
;
$
engine
=
new
WorkflowEngine
(
$
storage
,
$
spy
);
$
definition
= WorkflowBuilder::
create
(
'
retry-exhaust
'
)
->
addStep
(
'
always_fail
'
, AlwaysFailAction::class, retryAttempts:
2
)
->
build
();
expect
(
fn
() =>
$
engine
->
start
(
'
retry-fail
'
,
$
definition
->
toArray
(), []))
->
toThrow
(StepExecutionException::class);
});
test
(
'
does not retry when retryAttempts is 0
'
,
function
() {
$
storage
=
new
InMemoryStorage
;
$
spy
=
new
SpyEventDispatcher
;
$
engine
=
new
WorkflowEngine
(
$
storage
,
$
spy
);
$
definition
= WorkflowBuilder::
create
(
'
no-retry
'
)
->
addStep
(
'
fail_once
'
, AlwaysFailAction::class, retryAttempts:
0
)
->
build
();
expect
(
fn
() =>
$
engine
->
start
(
'
no-retry
'
,
$
definition
->
toArray
(), []))
->
toThrow
(StepExecutionException::class);
$
retryEvents
=
array_filter
(
$
spy
->
dispatched
,
fn
(
$
e
) =>
str_contains
(
get_class
(
$
e
),
'
StepRetried
'
));
expect
(
count
(
$
retryEvents
))->
toBe
(
0
);
});
});
Back
|
FazBrowse Home
|
New Git URL