Skip to content

Commit

Permalink
fix(ci): multiply timeouts on windows platform (#2137)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sylvlecl authored Sep 18, 2024
1 parent 1855bf4 commit 6ace98e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/prepare_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
33 changes: 21 additions & 12 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This file is part of the Antares project.

import contextlib
import os
import time
from typing import Callable

Expand All @@ -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}")

0 comments on commit 6ace98e

Please sign in to comment.