From c8c39013578b74a07aaeccd6ca2f046a69950204 Mon Sep 17 00:00:00 2001 From: Pontus Lurcock Date: Thu, 3 Aug 2023 15:46:52 +0200 Subject: [PATCH] Fix ComputeJobsRoutesTest.test_cancel_job This test was failing intermittently because the job sometimes completed before it had time to be cancelled; I've changed the job to execute an operation that includes a time delay to make sure that this doesn't happen. --- test/webapi/compute/test_routes.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/webapi/compute/test_routes.py b/test/webapi/compute/test_routes.py index 3630fc22b..cb7c980f7 100644 --- a/test/webapi/compute/test_routes.py +++ b/test/webapi/compute/test_routes.py @@ -18,7 +18,10 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. + import time +import xarray as xr +from xcube.webapi.compute.op.decorator import operation from ..helpers import RoutesTestCase @@ -150,18 +153,21 @@ def test_cancel_nonexistent_job(self): self.assertEqual(404, status) def test_cancel_job(self): + @operation + def slow_identity(dataset: xr.Dataset) -> xr.Dataset: + time.sleep(10) # Ensure the job runs long enough to be cancelled + return dataset + job1, status1 = self.fetch_json( '/compute/jobs', method="PUT", body={ - "operationId": "spatial_subset", + "operationId": "slow_identity", "parameters": { "dataset": "demo", - "bbox": [1, 51, 4, 52] }, "output": { - "datasetId": "demo_subset", - "title": "My demo subset" + "datasetId": "demo2", } } ) @@ -172,7 +178,6 @@ def test_cancel_job(self): self.assertEqual(job2['state']['status'], 'cancelled') def test_mldataset(self): - from xcube.webapi.compute.op.decorator import operation from xcube.core.mldataset import MultiLevelDataset @operation