Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
AURA
engine
Commits
e7ca792f
Commit
e7ca792f
authored
3 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Added test cases for EngineExecutor.
#78
parent
fcef1cfc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test.py
+109
-2
109 additions, 2 deletions
tests/test.py
with
109 additions
and
2 deletions
tests/test.py
+
109
−
2
View file @
e7ca792f
...
...
@@ -96,13 +96,13 @@ class TestEngineExecutor(unittest.TestCase):
def
test_single_executor
(
self
):
# Initialize stae and executor params
# Initialize sta
t
e and executor params
global_state
=
[
"
none
"
]
due_time
=
SU
.
timestamp
()
+
2
def
f
(
param
):
global_state
[
0
]
=
param
# Before the executor is done ther should be the initial value
# Before the executor is done ther
e
should be the initial value
e
=
EngineExecutor
(
"
RANDOM_NAMESPACE
"
,
None
,
due_time
,
f
,
"
hello world
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
self
.
assertNotEqual
(
"
hello world
"
,
global_state
[
0
])
...
...
@@ -113,6 +113,113 @@ class TestEngineExecutor(unittest.TestCase):
def
test_two_executors
(
self
):
# Initialize state and executor params
global_state
=
[
"
none
"
]
def
f
(
param
):
global_state
[
0
]
=
param
# Before the executor 1 is done there should be the initial value
due_time1
=
SU
.
timestamp
()
+
4
e1
=
EngineExecutor
(
"
EXECUTOR_1
"
,
None
,
due_time1
,
f
,
"
hello world from executor 1
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
self
.
assertNotEqual
(
"
hello world from executor 1
"
,
global_state
[
0
])
# Before the executor 2 is done there should be still the initial value
due_time2
=
SU
.
timestamp
()
+
2
e2
=
EngineExecutor
(
"
EXECUTOR_2
"
,
None
,
due_time2
,
f
,
"
hello world from executor 2
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
self
.
assertNotEqual
(
"
hello world from executor 2
"
,
global_state
[
0
])
# After 1 second there still should be the initial value
time
.
sleep
(
1
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# After 3 seconds max there should be the updated value from executor 2
time
.
sleep
(
2
)
self
.
assertEqual
(
"
hello world from executor 2
"
,
global_state
[
0
])
# After 5 seconds max there should be the updated value from executor 1
time
.
sleep
(
5
)
self
.
assertEqual
(
"
hello world from executor 1
"
,
global_state
[
0
])
def
test_parent_child_executors_in_order
(
self
):
# Initialize state and executor params
global_state
=
[
"
none
"
]
def
f
(
param
):
global_state
[
0
]
=
param
# Before the the parent is done there should be the initial value
due_time1
=
SU
.
timestamp
()
+
1
parent
=
EngineExecutor
(
"
EXECUTOR_PARENT
"
,
None
,
due_time1
,
f
,
"
hello world from parent
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# Before the the child is done there should be the initial value
due_time2
=
SU
.
timestamp
()
+
3
child
=
EngineExecutor
(
"
EXECUTOR_CHILD
"
,
parent
,
due_time2
,
f
,
"
hello world from child
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# After 0.5 seconds there still should be the initial value
time
.
sleep
(
0.5
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# After 2 seconds max there should be the updated value from parent executor
time
.
sleep
(
2
)
self
.
assertEqual
(
"
hello world from parent
"
,
global_state
[
0
])
# After 4 seconds max there should be the updated value from child executor
time
.
sleep
(
4
)
self
.
assertEqual
(
"
hello world from child
"
,
global_state
[
0
])
def
test_parent_child_executors_with_child_before
(
self
):
# Initialize state and executor params
global_state
=
[
"
none
"
,
"
never called by parent
"
]
def
f
(
param
):
global_state
[
0
]
=
param
if
param
==
"
hello world from parent
"
:
global_state
[
1
]
=
param
# Before the the parent is done there should be the initial value
due_time1
=
SU
.
timestamp
()
+
3
parent
=
EngineExecutor
(
"
EXECUTOR_PARENT
"
,
None
,
due_time1
,
f
,
"
hello world from parent
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# Before the the child is done there should be the initial value
due_time2
=
SU
.
timestamp
()
+
1
child
=
EngineExecutor
(
"
EXECUTOR_CHILD
"
,
parent
,
due_time2
,
f
,
"
hello world from child
"
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# After 0.5 seconds there still should be the initial value
time
.
sleep
(
0.5
)
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# After 2 seconds max there isn't a setting from the child yet, because it's waiting for the parent
time
.
sleep
(
2
)
self
.
assertNotEqual
(
"
hello world from child
"
,
global_state
[
0
])
# But the parent didn't set anything either, because it's scheduled for later
self
.
assertNotEqual
(
"
hello world from parent
"
,
global_state
[
0
])
self
.
assertEqual
(
"
none
"
,
global_state
[
0
])
# Double check if it has ever been called by parent
self
.
assertEqual
(
"
never called by parent
"
,
global_state
[
1
])
# After 4 seconds max there should be the updated value from parent & child
# Because the child is due before the parent, it is executed right away,
# hence overwriting the value just set by the parent
time
.
sleep
(
4
)
self
.
assertNotEqual
(
"
hello world from parent
"
,
global_state
[
0
])
self
.
assertEqual
(
"
hello world from child
"
,
global_state
[
0
])
# But we do not just believe what we expect, but check if it really has ever been called by a parent:
self
.
assertEqual
(
"
hello world from parent
"
,
global_state
[
1
])
if
__name__
==
'
__main__
'
:
unittest
.
main
()
\ No newline at end of file
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