From 6ace98ed2bec4f29b931412fb4bb3d701846ac97 Mon Sep 17 00:00:00 2001 From: Sylvain Leclerc Date: Wed, 18 Sep 2024 15:25:16 +0200 Subject: [PATCH] fix(ci): multiply timeouts on windows platform (#2137) The aim is to solve irrelevant failures on windows CI. It often fails when waiting for study upgrades, in particular. The PR re-activates the use of more workers (logical cores instead of CPUs). ANT-2043 --------- Signed-off-by: Sylvain Leclerc --- .github/workflows/main.yml | 2 +- tests/integration/prepare_proxy.py | 4 +-- .../test_download_matrices.py | 4 +-- tests/integration/utils.py | 33 ++++++++++++------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 91523a511d..604f8e54d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: pip install -r requirements-dev.txt - name: Test with pytest run: | - pytest --cov antarest --cov-report xml -n auto + pytest --cov antarest --cov-report xml -n logical - name: Archive code coverage results if: matrix.os == 'ubuntu-20.04' uses: actions/upload-artifact@v4 diff --git a/tests/integration/prepare_proxy.py b/tests/integration/prepare_proxy.py index 8fc52f2f55..47e5a33294 100644 --- a/tests/integration/prepare_proxy.py +++ b/tests/integration/prepare_proxy.py @@ -90,7 +90,7 @@ def copy_study_and_upgrade(self, ref_study_id: str, target_version: int) -> str: task_id = res.json() assert task_id - task = wait_task_completion(self.client, self.user_access_token, task_id, timeout=20) + task = wait_task_completion(self.client, self.user_access_token, task_id, base_timeout=20) assert task.status == TaskStatus.COMPLETED return study_id @@ -173,7 +173,7 @@ def generate_snapshot(self, variant_id: str, denormalize: bool = False, from_scr task_id = res.json() assert task_id - task = wait_task_completion(self.client, self.user_access_token, task_id, timeout=20) + task = wait_task_completion(self.client, self.user_access_token, task_id, base_timeout=20) assert task.status == TaskStatus.COMPLETED def create_area(self, study_id: str, *, name: str, country: str = "FR") -> t.Dict[str, t.Any]: diff --git a/tests/integration/raw_studies_blueprint/test_download_matrices.py b/tests/integration/raw_studies_blueprint/test_download_matrices.py index 2228a71388..499bd8b587 100644 --- a/tests/integration/raw_studies_blueprint/test_download_matrices.py +++ b/tests/integration/raw_studies_blueprint/test_download_matrices.py @@ -53,7 +53,7 @@ def copy_upgrade_study(self, ref_study_id, target_version=820): task_id = res.json() assert task_id - task = wait_task_completion(self.client, self.user_access_token, task_id, timeout=20) + task = wait_task_completion(self.client, self.user_access_token, task_id, base_timeout=20) assert task.status == TaskStatus.COMPLETED return study_820_id @@ -91,7 +91,7 @@ def generate_snapshot(self, variant_id: str, denormalize=False, from_scratch=Tru task_id = res.json() assert task_id - task = wait_task_completion(self.client, self.user_access_token, task_id, timeout=20) + task = wait_task_completion(self.client, self.user_access_token, task_id, base_timeout=20) assert task.status == TaskStatus.COMPLETED def create_area(self, parent_id, *, name: str, country: str = "FR") -> str: diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 7812f4d371..fa5a34f286 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -11,6 +11,7 @@ # This file is part of the Antares project. import contextlib +import os import time from typing import Callable @@ -29,24 +30,32 @@ def wait_for(predicate: Callable[[], bool], timeout: float = 10, sleep_time: flo raise TimeoutError(f"task is still in progress after {timeout} seconds") +IS_WINDOWS = os.name == "nt" +TIMEOUT_MULTIPLIER = 2 if IS_WINDOWS else 1 + + def wait_task_completion( client: TestClient, access_token: str, task_id: str, *, - timeout: float = 10, + base_timeout: float = 10, ) -> TaskDTO: - end_time = time.time() + timeout - while time.time() < end_time: - time.sleep(0.1) - res = client.request( - "GET", - f"/v1/tasks/{task_id}", - headers={"Authorization": f"Bearer {access_token}"}, - json={"wait_for_completion": True}, - ) - assert res.status_code == 200 + """ + base_timeout is multiplied by 2 on windows to cope with slow CI + """ + timeout = TIMEOUT_MULTIPLIER * base_timeout + params = {"wait_for_completion": True, "timeout": timeout} + res = client.request( + "GET", + f"/v1/tasks/{task_id}", + headers={"Authorization": f"Bearer {access_token}"}, + params=params, + ) + if res.status_code == 200: task = TaskDTO(**res.json()) if task.status not in {TaskStatus.PENDING, TaskStatus.RUNNING}: return task - raise TimeoutError(f"{timeout} seconds") + elif res.status_code == 408: + raise TimeoutError(f"{timeout} seconds") + raise ValueError(f"Unexpected status code {res.status_code}")