From 1c72f868592f0fa46564bc532c2a132e0a966d62 Mon Sep 17 00:00:00 2001 From: Chris Harris Date: Mon, 16 Dec 2024 16:45:19 +0000 Subject: [PATCH 1/2] Pass cached=False when fetching job status --- src/sfapi_client/_async/jobs.py | 4 +++- src/sfapi_client/_sync/jobs.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sfapi_client/_async/jobs.py b/src/sfapi_client/_async/jobs.py index 2c13f10..da9e3f1 100644 --- a/src/sfapi_client/_async/jobs.py +++ b/src/sfapi_client/_async/jobs.py @@ -24,7 +24,9 @@ async def _fetch_raw_state( partition: Optional[str] = None, sacct: Optional[bool] = False, ): - params = {"sacct": sacct} + # For now we are pass cached=False to ensure we don't + # break compatibility + params = {"sacct": sacct, "cached": False} job_url = f"compute/jobs/{compute.name}" diff --git a/src/sfapi_client/_sync/jobs.py b/src/sfapi_client/_sync/jobs.py index 22308c0..70bfa9c 100644 --- a/src/sfapi_client/_sync/jobs.py +++ b/src/sfapi_client/_sync/jobs.py @@ -24,7 +24,9 @@ def _fetch_raw_state( partition: Optional[str] = None, sacct: Optional[bool] = False, ): - params = {"sacct": sacct} + # For now we are pass cached=False to ensure we don't + # break compatibility + params = {"sacct": sacct, "cached": False} job_url = f"compute/jobs/{compute.name}" From 4f3d77aa9647d1c4dcef7ad13c47c78f5cbc3c37 Mon Sep 17 00:00:00 2001 From: Chris Harris Date: Mon, 16 Dec 2024 16:46:16 +0000 Subject: [PATCH 2/2] Remove dev api instance requirement from some tests The patches are now in prod --- src/sfapi_client/_sync/client.py | 5 +---- tests/test_jobs.py | 28 ++++------------------------ tests/test_jobs_async.py | 17 ++--------------- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/src/sfapi_client/_sync/client.py b/src/sfapi_client/_sync/client.py index 823ec1e..039ab2a 100644 --- a/src/sfapi_client/_sync/client.py +++ b/src/sfapi_client/_sync/client.py @@ -383,10 +383,7 @@ def get(self, url: str, params: Dict[str, Any] = {}) -> httpx.Response: stop=tenacity.stop_after_attempt(MAX_RETRY), ) def post( - self, - url: str, - data: Dict[str, Any] = None, - json: Dict[str, Any] = None + self, url: str, data: Dict[str, Any] = None, json: Dict[str, Any] = None ) -> httpx.Response: client = self._http_client() diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 2f0f787..497f971 100755 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -2,7 +2,6 @@ from concurrent.futures import ThreadPoolExecutor import time -from sfapi_client import Client from sfapi_client.jobs import JobState from sfapi_client.compute import Compute from sfapi_client.jobs import JobSqueue @@ -52,22 +51,13 @@ def test_complete_timeout(authenticated_client, test_job_path, test_machine): job.complete(timeout=10) -@pytest.mark.api_dev def test_job_monitor_check_request( mocker, - dev_client_id, - dev_client_secret, + authenticated_client, test_job_path, test_machine, - dev_api_url, - dev_token_url, ): - with Client( - client_id=dev_client_id, - secret=dev_client_secret, - api_base_url=dev_api_url, - token_url=dev_token_url, - ) as client: + with authenticated_client as client: num_jobs = 10 _fetch_jobs = mocker.patch("sfapi_client._monitor._fetch_jobs") @@ -122,24 +112,14 @@ def _jobs(*arg, **kwargs): assert len(ids) == num_jobs -# We currently run this in api-dev as its a new feature deployed there -@pytest.mark.api_dev def test_job_monitor_multiple_threads( - dev_client_id, - dev_client_secret, + authenticated_client, test_job_path, test_machine, - dev_api_url, - dev_token_url, ): num_jobs = 5 - with Client( - client_id=dev_client_id, - secret=dev_client_secret, - api_base_url=dev_api_url, - token_url=dev_token_url, - ) as client: + with authenticated_client as client: machine = client.compute(test_machine) jobs = [] diff --git a/tests/test_jobs_async.py b/tests/test_jobs_async.py index 71d54be..3c1b5ab 100755 --- a/tests/test_jobs_async.py +++ b/tests/test_jobs_async.py @@ -1,7 +1,6 @@ import pytest import asyncio -from sfapi_client import AsyncClient from sfapi_client.compute import AsyncCompute from sfapi_client.jobs import AsyncJobSqueue, AsyncJobSacct, JobState @@ -162,23 +161,11 @@ async def test_job_monitor_job_types(async_authenticated_client, mocker, test_ma assert kwargs["job_type"] == AsyncJobSacct -# We currently run this in api-dev as its a new feature deployed there -@pytest.mark.api_dev @pytest.mark.asyncio async def test_job_monitor_gather( - dev_client_id, - dev_client_secret, - test_job_path, - test_machine, - dev_api_url, - dev_token_url, + async_authenticated_client, test_job_path, test_machine ): - async with AsyncClient( - client_id=dev_client_id, - secret=dev_client_secret, - api_base_url=dev_api_url, - token_url=dev_token_url, - ) as client: + async with async_authenticated_client as client: machine = await client.compute(test_machine) submit_tasks = []