Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ewoksppf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
workflow
ewoks
ewoksppf
Merge requests
!101
Draft: Add test of execution of workflow with self-triggering task
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Add test of execution of workflow with self-triggering task
self-trigger-test
into
main
Overview
1
Commits
1
Pipelines
3
Changes
1
Open
Loic Huder
requested to merge
self-trigger-test
into
main
6 months ago
Overview
1
Commits
1
Pipelines
3
Changes
1
Expand
For
#16
Needs
ewokscore!236 (merged)
0
0
Merge request reports
Viewing commit
f31f5b4b
Show latest version
1 file
+
142
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
f31f5b4b
Add test of execution of workflow with self-triggering task
· f31f5b4b
Loic Huder
authored
6 months ago
src/ewoksppf/tests/test_self_triggering_task.py
0 → 100644
+
142
−
0
Options
import
pytest
import
os.path
from
ewokscore
import
Task
from
ewoksppf
import
execute_graph
qualname
=
__name__
def
test_explicit_start_node_on_self_triggering_node
(
tmpdir
):
"""
Workflow:
- LOOP depends on itself (self-triggering task).
- SAVE depends on LOOP and CONFIG
- CONFIG does not depend on anything
/|
/ |
LOOP -- SAVE
/
/
/
CONFIG
This test tests that, while graph analysis considers that the only
start node is CONFIG, it is possible to set `start_node` for LOOP
and make it a start node so that SAVE can get inputs from LOOP and
CONFIG.
"""
class
ConfigTask
(
Task
,
input_names
=
[
"
filename
"
],
output_names
=
[
"
config
"
]):
def
run
(
self
):
self
.
outputs
.
config
=
{
"
filename
"
:
self
.
inputs
.
filename
}
class
LoopTask
(
Task
,
input_names
=
[
"
i
"
,
"
n
"
],
output_names
=
[
"
i
"
,
"
keep_looping
"
],
):
def
run
(
self
):
self
.
outputs
.
i
=
self
.
inputs
.
i
+
1
self
.
outputs
.
keep_looping
=
self
.
outputs
.
i
<
self
.
inputs
.
n
class
SaveTask
(
Task
,
input_names
=
[
"
config
"
],
optional_input_names
=
[
"
i
"
],
output_names
=
[
"
result
"
],
):
def
run
(
self
):
if
self
.
missing_inputs
.
i
:
raise
RuntimeError
(
"
LOOP not executed!
"
)
config
=
self
.
inputs
.
config
with
open
(
config
[
"
filename
"
],
"
a
"
)
as
out_file
:
out_file
.
write
(
f
"
LOOP executed:
{
self
.
inputs
.
i
}
"
)
workflow
=
{
"
graph
"
:
{
"
id
"
:
"
testworkflow
"
},
"
nodes
"
:
[
{
"
id
"
:
"
CONFIG
"
,
"
task_type
"
:
"
class
"
,
"
task_identifier
"
:
f
"
{
qualname
}
.ConfigTask
"
,
},
{
"
id
"
:
"
LOOP
"
,
"
task_type
"
:
"
class
"
,
"
task_identifier
"
:
f
"
{
qualname
}
.LoopTask
"
,
},
{
"
id
"
:
"
SAVE
"
,
"
task_type
"
:
"
class
"
,
"
task_identifier
"
:
f
"
{
qualname
}
.SaveTask
"
,
},
],
"
links
"
:
[
{
"
source
"
:
"
LOOP
"
,
"
target
"
:
"
LOOP
"
,
"
data_mapping
"
:
[{
"
source_output
"
:
"
i
"
,
"
target_input
"
:
"
i
"
}],
"
conditions
"
:
[{
"
source_output
"
:
"
keep_looping
"
,
"
value
"
:
True
}],
},
{
"
source
"
:
"
LOOP
"
,
"
target
"
:
"
SAVE
"
,
"
data_mapping
"
:
[{
"
source_output
"
:
"
i
"
,
"
target_input
"
:
"
i
"
}],
},
{
"
source
"
:
"
CONFIG
"
,
"
target
"
:
"
SAVE
"
,
"
data_mapping
"
:
[{
"
source_output
"
:
"
config
"
,
"
target_input
"
:
"
config
"
}],
},
],
}
filename
=
str
(
tmpdir
/
"
test.txt
"
)
max_iterations
=
10
inputs
=
[
{
"
task_identifier
"
:
f
"
{
qualname
}
.ConfigTask
"
,
"
name
"
:
"
filename
"
,
"
value
"
:
filename
,
},
{
"
task_identifier
"
:
f
"
{
qualname
}
.LoopTask
"
,
"
name
"
:
"
i
"
,
"
value
"
:
0
,
},
{
"
task_identifier
"
:
f
"
{
qualname
}
.LoopTask
"
,
"
name
"
:
"
n
"
,
"
value
"
:
max_iterations
,
},
]
# Execute without setting `force_start_node` in the LOOP node: the SAVE task fails.
with
pytest
.
raises
(
RuntimeError
)
as
e
:
execute_graph
(
workflow
,
scaling_workers
=
False
,
pool_type
=
"
thread
"
,
inputs
=
inputs
,
)
assert
str
(
e
)
==
"
RuntimeError: Task
'
SAVE
'
failed
"
assert
not
os
.
path
.
exists
(
filename
)
# Execute with `force_start_node` in the LOOP node; the SAVE task runs and the file exists.
loop_node
=
workflow
[
"
nodes
"
][
1
]
assert
loop_node
[
"
id
"
]
==
"
LOOP
"
loop_node
[
"
force_start_node
"
]
=
True
execute_graph
(
workflow
,
scaling_workers
=
False
,
pool_type
=
"
thread
"
,
inputs
=
inputs
,
)
with
open
(
filename
)
as
_file
:
txt
=
_file
.
read
()
for
i
in
range
(
max_iterations
):
assert
str
(
i
)
in
txt
Loading