Add test that ensures cancelling job in admin interface works

This commit is contained in:
mvdbeek
2019-06-26 12:08:49 +02:00
parent 96c001c565
commit 5016dedac7
+35 -13
View File
@@ -18,29 +18,51 @@ class LocalJobCancellationTestCase(integration_util.IntegrationTestCase):
super(LocalJobCancellationTestCase, self).setUp()
self.dataset_populator = DatasetPopulator(self.galaxy_interactor)
def setup_cat_data_and_sleep(self, history_id):
hda1 = self.dataset_populator.new_dataset(history_id, content="1 2 3")
running_inputs = {
"input1": {"src": "hda", "id": hda1["id"]},
"sleep_time": 240,
}
running_response = self.dataset_populator.run_tool(
"cat_data_and_sleep",
running_inputs,
history_id,
assert_ok=False,
).json()
job_dict = running_response["jobs"][0]
return job_dict
def test_cancel_job_with_admin_message(self):
with self.dataset_populator.test_history() as history_id:
job_dict = self.setup_cat_data_and_sleep(history_id)
self.galaxy_interactor.wait_for(lambda: self._get("jobs/%s" % job_dict['id']).json()['state'] != 'running',
maxseconds=60)
app = self._app
sa_session = app.model.context.current
Job = app.model.Job
job = sa_session.query(Job).filter_by(tool_id="cat_data_and_sleep").order_by(Job.create_time.desc()).first()
# This is how the admin controller code cancels a job
job.job_stderr = 'admin cancelled job'
job.set_state(app.model.Job.states.DELETED_NEW)
sa_session.add(job)
sa_session.flush()
self.galaxy_interactor.wait_for(lambda: self._get("jobs/%s" % job_dict['id']).json()['state'] != 'error',
maxseconds=60)
def test_kill_process(self):
"""
"""
with self.dataset_populator.test_history() as history_id:
hda1 = self.dataset_populator.new_dataset(history_id, content="1 2 3")
running_inputs = {
"input1": {"src": "hda", "id": hda1["id"]},
"sleep_time": 240,
}
running_response = self.dataset_populator.run_tool(
"cat_data_and_sleep",
running_inputs,
history_id,
assert_ok=False,
).json()
job_dict = running_response["jobs"][0]
job_dict = self.setup_cat_data_and_sleep(history_id)
app = self._app
sa_session = app.model.context.current
external_id = None
state = False
Job = app.model.Job
job = sa_session.query(app.model.Job).filter_by(tool_id="cat_data_and_sleep").one()
job = sa_session.query(Job).filter_by(tool_id="cat_data_and_sleep").order_by(Job.create_time.desc()).first()
# Not checking the state here allows the change from queued to running to overwrite
# the change from queued to deleted_new in the API thread - this is a problem because
# the job will still run. See issue https://github.com/galaxyproject/galaxy/issues/4960.