Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
afd8b703
Commit
afd8b703
authored
4 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-666
: added cancel tests for scheduled and started subtask
parent
6f36ad0a
No related branches found
No related tags found
1 merge request
!426
Resolve TMSS-666
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/test/t_scheduling.py
+72
-3
72 additions, 3 deletions
SAS/TMSS/backend/test/t_scheduling.py
with
72 additions
and
3 deletions
SAS/TMSS/backend/test/t_scheduling.py
+
72
−
3
View file @
afd8b703
...
@@ -24,12 +24,22 @@ import unittest
...
@@ -24,12 +24,22 @@ import unittest
from
unittest
import
mock
from
unittest
import
mock
import
logging
import
logging
logger
=
logging
.
getLogger
(
'
lofar
'
+
__name__
)
logger
=
logging
.
getLogger
(
'
lofar
.
'
+
__name__
)
logging
.
basicConfig
(
format
=
'
%(asctime)s %(levelname)s %(message)s
'
,
level
=
logging
.
INFO
)
logging
.
basicConfig
(
format
=
'
%(asctime)s %(levelname)s %(message)s
'
,
level
=
logging
.
INFO
)
from
lofar.common.test_utils
import
exit_with_skipped_code_if_skip_integration_tests
from
lofar.common.test_utils
import
exit_with_skipped_code_if_skip_integration_tests
exit_with_skipped_code_if_skip_integration_tests
()
exit_with_skipped_code_if_skip_integration_tests
()
# create a module-wide TemporaryExchange, and use it in all communications between TMSSTestEnvironment, RA and ObservationControl
from
lofar.messaging.messagebus
import
TemporaryExchange
tmp_exchange
=
TemporaryExchange
(
'
t_scheduling
'
)
tmp_exchange
.
open
()
# override DEFAULT_BUSNAME with tmp exchange, some modules import from lofar.messaging others from lofar.messaging.config...
import
lofar
lofar
.
messaging
.
DEFAULT_BUSNAME
=
tmp_exchange
.
address
lofar
.
messaging
.
config
.
DEFAULT_BUSNAME
=
tmp_exchange
.
address
# before we import any django modules the DJANGO_SETTINGS_MODULE, TMSS_LDAPCREDENTIALS and TMSS_DBCREDENTIALS need to be known/set.
# before we import any django modules the DJANGO_SETTINGS_MODULE, TMSS_LDAPCREDENTIALS and TMSS_DBCREDENTIALS need to be known/set.
# import and start an isolated RATestEnvironment and TMSSTestEnvironment (with fresh database and attached django and ldap server on free ports)
# import and start an isolated RATestEnvironment and TMSSTestEnvironment (with fresh database and attached django and ldap server on free ports)
# this automagically sets the required DJANGO_SETTINGS_MODULE, TMSS_LDAPCREDENTIALS and TMSS_DBCREDENTIALS envvars.
# this automagically sets the required DJANGO_SETTINGS_MODULE, TMSS_LDAPCREDENTIALS and TMSS_DBCREDENTIALS envvars.
...
@@ -37,7 +47,8 @@ from lofar.sas.tmss.test.test_environment import TMSSTestEnvironment
...
@@ -37,7 +47,8 @@ from lofar.sas.tmss.test.test_environment import TMSSTestEnvironment
tmss_test_env
=
TMSSTestEnvironment
(
populate_schemas
=
True
,
populate_test_data
=
False
,
start_ra_test_environment
=
True
,
tmss_test_env
=
TMSSTestEnvironment
(
populate_schemas
=
True
,
populate_test_data
=
False
,
start_ra_test_environment
=
True
,
start_postgres_listener
=
False
,
start_subtask_scheduler
=
False
,
start_dynamic_scheduler
=
False
,
start_postgres_listener
=
False
,
start_subtask_scheduler
=
False
,
start_dynamic_scheduler
=
False
,
enable_viewflow
=
False
)
enable_viewflow
=
False
,
exchange
=
tmp_exchange
.
address
)
try
:
try
:
tmss_test_env
.
start
()
tmss_test_env
.
start
()
...
@@ -45,11 +56,13 @@ except Exception as e:
...
@@ -45,11 +56,13 @@ except Exception as e:
logger
.
exception
(
e
)
logger
.
exception
(
e
)
tmss_test_env
.
stop
()
tmss_test_env
.
stop
()
tmp_exchange
.
close
()
exit
(
1
)
exit
(
1
)
# tell unittest to stop (and automagically cleanup) the test database once all testing is done.
# tell unittest to stop (and automagically cleanup) the test database once all testing is done.
def
tearDownModule
():
def
tearDownModule
():
tmss_test_env
.
stop
()
tmss_test_env
.
stop
()
tmp_exchange
.
close
()
from
lofar.sas.tmss.test.tmss_test_data_django_models
import
*
from
lofar.sas.tmss.test.tmss_test_data_django_models
import
*
...
@@ -62,7 +75,8 @@ from lofar.sas.resourceassignment.resourceassigner.rarpc import RARPC
...
@@ -62,7 +75,8 @@ from lofar.sas.resourceassignment.resourceassigner.rarpc import RARPC
from
lofar.sas.tmss.tmss.tmssapp
import
models
from
lofar.sas.tmss.tmss.tmssapp
import
models
from
lofar.sas.tmss.tmss.tmssapp.subtasks
import
*
from
lofar.sas.tmss.tmss.tmssapp.subtasks
import
*
from
lofar.sas.tmss.tmss.tmssapp.tasks
import
*
from
lofar.sas.tmss.tmss.tmssapp.tasks
import
*
from
lofar.messaging.rpc
import
RPCService
,
ServiceMessageHandler
import
threading
def
create_subtask_object_for_testing
(
subtask_type_value
,
subtask_state_value
):
def
create_subtask_object_for_testing
(
subtask_type_value
,
subtask_state_value
):
"""
"""
...
@@ -212,6 +226,61 @@ class SchedulingTest(unittest.TestCase):
...
@@ -212,6 +226,61 @@ class SchedulingTest(unittest.TestCase):
subtask
=
client
.
get_subtask
(
subtask_id
)
subtask
=
client
.
get_subtask
(
subtask_id
)
self
.
assertEqual
(
'
cancelled
'
,
subtask
[
'
state_value
'
])
self
.
assertEqual
(
'
cancelled
'
,
subtask
[
'
state_value
'
])
def
test_cancel_scheduled_observation_subtask
(
self
):
with
tmss_test_env
.
create_tmss_client
()
as
client
:
subtask_template
=
client
.
get_subtask_template
(
"
observation control
"
)
spec
=
get_default_json_object_for_schema
(
subtask_template
[
'
schema
'
])
spec
[
'
stations
'
][
'
digital_pointings
'
][
0
][
'
subbands
'
]
=
[
0
]
subtask
=
self
.
_create_target_observation_subtask
(
spec
)
subtask_id
=
subtask
[
'
id
'
]
client
.
set_subtask_status
(
subtask_id
,
'
defined
'
)
# scheduling should succeed
subtask
=
client
.
schedule_subtask
(
subtask_id
)
self
.
assertEqual
(
'
scheduled
'
,
subtask
[
'
state_value
'
])
# cancel it...
subtask
=
client
.
cancel_subtask
(
subtask_id
)
self
.
assertEqual
(
'
cancelled
'
,
subtask
[
'
state_value
'
])
def
test_cancel_started_observation_subtask
(
self
):
with
tmss_test_env
.
create_tmss_client
()
as
client
:
subtask_template
=
client
.
get_subtask_template
(
"
observation control
"
)
spec
=
get_default_json_object_for_schema
(
subtask_template
[
'
schema
'
])
spec
[
'
stations
'
][
'
digital_pointings
'
][
0
][
'
subbands
'
]
=
[
0
]
subtask
=
self
.
_create_target_observation_subtask
(
spec
)
subtask_id
=
subtask
[
'
id
'
]
client
.
set_subtask_status
(
subtask_id
,
'
defined
'
)
# scheduling should succeed
subtask
=
client
.
schedule_subtask
(
subtask_id
)
self
.
assertEqual
(
'
scheduled
'
,
subtask
[
'
state_value
'
])
# mimic that the obs was started and is now running
client
.
set_subtask_status
(
subtask_id
,
'
starting
'
)
client
.
set_subtask_status
(
subtask_id
,
'
started
'
)
observation_killed
=
threading
.
Event
()
class
MockObsControlMessageHandler
(
ServiceMessageHandler
):
def
__init__
(
self
):
super
(
MockObsControlMessageHandler
,
self
).
__init__
()
self
.
register_service_method
(
"
AbortObservation
"
,
self
.
abort_observation
)
def
abort_observation
(
self
,
sas_id
):
observation_killed
.
set
()
return
{
'
aborted
'
:
True
}
with
RPCService
(
service_name
=
lofar
.
mac
.
config
.
DEFAULT_OBSERVATION_CONTROL_SERVICE_NAME
,
handler_type
=
MockObsControlMessageHandler
,
exchange
=
tmp_exchange
.
address
):
# cancel observation subtask... should kill the running observation
# check that ObservationControlRPCClient.abort_observation was called
subtask
=
client
.
cancel_subtask
(
subtask_id
)
self
.
assertEqual
(
'
cancelled
'
,
subtask
[
'
state_value
'
])
observation_killed
.
wait
(
10
)
self
.
assertTrue
(
observation_killed
.
is_set
())
def
test_schedule_observation_subtask_with_one_blocking_reservation_failed
(
self
):
def
test_schedule_observation_subtask_with_one_blocking_reservation_failed
(
self
):
"""
"""
Set (Resource Assigner) station CS001 to reserved
Set (Resource Assigner) station CS001 to reserved
...
...
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