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
Commits
348770d6
Commit
348770d6
authored
6 months ago
by
Loic Huder
Browse files
Options
Downloads
Patches
Plain Diff
Add test of execution of workflow with self-triggering task
parent
c0928678
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#193750
failed
6 months ago
Stage: test
Stage: style
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ewoksppf/tests/test_self_triggering_task.py
+142
-0
142 additions, 0 deletions
src/ewoksppf/tests/test_self_triggering_task.py
with
142 additions
and
0 deletions
src/ewoksppf/tests/test_self_triggering_task.py
0 → 100644
+
142
−
0
View file @
348770d6
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 `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 setting `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
[
"
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment