From 5016dedac73e65b4bc07f0341e216d071ba1c740 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 26 Jun 2019 11:23:11 +0200 Subject: [PATCH] Add test that ensures cancelling job in admin interface works --- .../test_local_job_cancellation.py | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/test/integration/test_local_job_cancellation.py b/test/integration/test_local_job_cancellation.py index abcaa0a1576..06166c242e3 100644 --- a/test/integration/test_local_job_cancellation.py +++ b/test/integration/test_local_job_cancellation.py @@ -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.