From cebc815891fbd252e2cbbc0ec0998d1df69ade0e Mon Sep 17 00:00:00 2001 From: fschuch Date: Tue, 3 Jan 2023 15:00:22 -0300 Subject: [PATCH 1/4] ASP-2438 speed up tests on Jobbergate API by restricting the scope of time consuming fixtures --- .../jobbergate_api/tests/apps/applications/test_routers.py | 3 +++ .../jobbergate_api/tests/apps/job_scripts/test_routers.py | 3 +++ .../jobbergate_api/tests/apps/job_submissions/test_routers.py | 3 +++ jobbergate-api/jobbergate_api/tests/conftest.py | 3 +-- jobbergate-api/jobbergate_api/tests/test_pagination.py | 2 ++ jobbergate-api/jobbergate_api/tests/test_storage.py | 3 +++ 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py index b8101cf4..a124f70a 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py @@ -15,6 +15,9 @@ from jobbergate_api.storage import database, fetch_instance +pytestmark = pytest.mark.usefixtures("startup_event_force") + + @pytest.mark.asyncio async def test_create_application( fill_application_data, diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py index 0578e3bd..c32a1abd 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py @@ -19,6 +19,9 @@ from jobbergate_api.storage import database +pytestmark = pytest.mark.usefixtures("startup_event_force") + + @pytest.fixture def job_script_data_as_string(): """ diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py index 41edc746..1a51d59b 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py @@ -17,6 +17,9 @@ from jobbergate_api.storage import database +pytestmark = pytest.mark.usefixtures("startup_event_force") + + @pytest.mark.asyncio async def test_create_job_submission__with_client_id_in_token( fill_application_data, diff --git a/jobbergate-api/jobbergate_api/tests/conftest.py b/jobbergate-api/jobbergate_api/tests/conftest.py index 5d2f9970..e9aca115 100644 --- a/jobbergate-api/jobbergate_api/tests/conftest.py +++ b/jobbergate-api/jobbergate_api/tests/conftest.py @@ -56,8 +56,7 @@ async def enforce_empty_database(database_engine): metadata.drop_all(database_engine) -@pytest.fixture(autouse=True) -@pytest.mark.enforce_empty_database() +@pytest.fixture() async def startup_event_force(): """ Force the async event loop to begin. diff --git a/jobbergate-api/jobbergate_api/tests/test_pagination.py b/jobbergate-api/jobbergate_api/tests/test_pagination.py index 8b24d7ff..8a64d70c 100644 --- a/jobbergate-api/jobbergate_api/tests/test_pagination.py +++ b/jobbergate-api/jobbergate_api/tests/test_pagination.py @@ -12,6 +12,8 @@ from jobbergate_api.pagination import Pagination, Response, package_response from jobbergate_api.storage import database +pytestmark = pytest.mark.usefixtures("startup_event_force") + def test_init_fails_on_invalid_parameters(): """ diff --git a/jobbergate-api/jobbergate_api/tests/test_storage.py b/jobbergate-api/jobbergate_api/tests/test_storage.py index 7c6d0ce5..04724015 100644 --- a/jobbergate-api/jobbergate_api/tests/test_storage.py +++ b/jobbergate-api/jobbergate_api/tests/test_storage.py @@ -11,6 +11,9 @@ from jobbergate_api.storage import build_db_url, database, sort_clause +pytestmark = pytest.mark.usefixtures("startup_event_force") + + def test_build_db_url__creates_database_url_from_parts(tweak_settings): """ Provide a test ase for the ``build_db_url()`` function. From e15e0814da4030e964c76227d93ed8b72d9a146c Mon Sep 17 00:00:00 2001 From: fschuch Date: Tue, 3 Jan 2023 17:24:50 -0300 Subject: [PATCH 2/4] ASP-2438 cache packages dependencies on CI --- .github/workflows/test_on_push.yaml | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test_on_push.yaml b/.github/workflows/test_on_push.yaml index 6d313b0b..0f5975e7 100644 --- a/.github/workflows/test_on_push.yaml +++ b/.github/workflows/test_on_push.yaml @@ -1,4 +1,4 @@ -name: 'Test' +name: "Test" on: push: @@ -9,7 +9,7 @@ on: jobs: api-tests: name: "jobbergate-api tests" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" services: test-db: image: postgres @@ -25,14 +25,15 @@ jobs: ports: - 5433:5432 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - architecture: 'x64' - - uses: Gr1N/setup-poetry@v7 + - uses: actions/checkout@v3 + - name: Install poetry + run: pipx install poetry==1.1.14 + - uses: actions/setup-python@v4 with: - poetry-version: 1.1.14 + python-version: "3.8" + architecture: "x64" + cache: "poetry" + cache-dependency-path: jobbergate-api/poetry.lock - name: "run quality control checks" working-directory: jobbergate-api env: @@ -41,25 +42,25 @@ jobs: TEST_DATABASE_USER: test TEST_DATABASE_PSWD: test-pswd TEST_DATABASE_NAME: test-jobbergate - POETRY_HTTP_BASIC_PYPICLOUD_USERNAME: admin - POETRY_HTTP_BASIC_PYPICLOUD_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: make qa + run: | + poetry env use "3.8" + make qa cli-tests: name: "jobbergate-cli tests" runs-on: "ubuntu-20.04" steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Install poetry + run: pipx install poetry==1.1.14 + - uses: actions/setup-python@v4 with: python-version: "3.6" - architecture: 'x64' - - uses: Gr1N/setup-poetry@v7 - with: - poetry-version: 1.1.14 + architecture: "x64" + cache: "poetry" + cache-dependency-path: jobbergate-cli/poetry.lock - name: "run quality control checks" working-directory: jobbergate-cli - env: - POETRY_HTTP_BASIC_PYPICLOUD_USERNAME: admin - POETRY_HTTP_BASIC_PYPICLOUD_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: make qa + run: | + poetry env use "3.6" + make qa From c6fec610cd62104228948ba7452e0e85ec61ddf8 Mon Sep 17 00:00:00 2001 From: fschuch Date: Tue, 3 Jan 2023 17:31:59 -0300 Subject: [PATCH 3/4] ASP-2438 format imports --- .../jobbergate_api/tests/apps/applications/test_routers.py | 1 - .../jobbergate_api/tests/apps/job_scripts/test_routers.py | 1 - .../jobbergate_api/tests/apps/job_submissions/test_routers.py | 1 - jobbergate-api/jobbergate_api/tests/test_storage.py | 1 - 4 files changed, 4 deletions(-) diff --git a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py index a124f70a..2ec30bb4 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py @@ -14,7 +14,6 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database, fetch_instance - pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py index c32a1abd..d08cf095 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py @@ -18,7 +18,6 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database - pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py index 1a51d59b..e76d70b4 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py @@ -16,7 +16,6 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database - pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/test_storage.py b/jobbergate-api/jobbergate_api/tests/test_storage.py index 04724015..67de4d00 100644 --- a/jobbergate-api/jobbergate_api/tests/test_storage.py +++ b/jobbergate-api/jobbergate_api/tests/test_storage.py @@ -10,7 +10,6 @@ from jobbergate_api.metadata import metadata from jobbergate_api.storage import build_db_url, database, sort_clause - pytestmark = pytest.mark.usefixtures("startup_event_force") From 914b3309dca82c42688509660c024b7e9e5b984f Mon Sep 17 00:00:00 2001 From: fschuch Date: Wed, 4 Jan 2023 16:54:59 -0300 Subject: [PATCH 4/4] ASP-2438 code review add comments explaining the use of the fixture startup_event_force --- .../jobbergate_api/tests/apps/applications/test_routers.py | 2 ++ .../jobbergate_api/tests/apps/job_scripts/test_routers.py | 2 ++ .../jobbergate_api/tests/apps/job_submissions/test_routers.py | 2 ++ jobbergate-api/jobbergate_api/tests/test_pagination.py | 2 ++ jobbergate-api/jobbergate_api/tests/test_storage.py | 2 ++ 5 files changed, 10 insertions(+) diff --git a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py index 2ec30bb4..1d42b6df 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/applications/test_routers.py @@ -14,6 +14,8 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database, fetch_instance +# Force the async event loop at the app to begin. +# Since this is a time consuming fixture, it is just used where strict necessary. pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py index d08cf095..9f7afdd2 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_scripts/test_routers.py @@ -18,6 +18,8 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database +# Force the async event loop at the app to begin. +# Since this is a time consuming fixture, it is just used where strict necessary. pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py index e76d70b4..986914b2 100644 --- a/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py +++ b/jobbergate-api/jobbergate_api/tests/apps/job_submissions/test_routers.py @@ -16,6 +16,8 @@ from jobbergate_api.apps.permissions import Permissions from jobbergate_api.storage import database +# Force the async event loop at the app to begin. +# Since this is a time consuming fixture, it is just used where strict necessary. pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/test_pagination.py b/jobbergate-api/jobbergate_api/tests/test_pagination.py index 8a64d70c..e649b899 100644 --- a/jobbergate-api/jobbergate_api/tests/test_pagination.py +++ b/jobbergate-api/jobbergate_api/tests/test_pagination.py @@ -12,6 +12,8 @@ from jobbergate_api.pagination import Pagination, Response, package_response from jobbergate_api.storage import database +# Force the async event loop at the app to begin. +# Since this is a time consuming fixture, it is just used where strict necessary. pytestmark = pytest.mark.usefixtures("startup_event_force") diff --git a/jobbergate-api/jobbergate_api/tests/test_storage.py b/jobbergate-api/jobbergate_api/tests/test_storage.py index 67de4d00..69f871c9 100644 --- a/jobbergate-api/jobbergate_api/tests/test_storage.py +++ b/jobbergate-api/jobbergate_api/tests/test_storage.py @@ -10,6 +10,8 @@ from jobbergate_api.metadata import metadata from jobbergate_api.storage import build_db_url, database, sort_clause +# Force the async event loop at the app to begin. +# Since this is a time consuming fixture, it is just used where strict necessary. pytestmark = pytest.mark.usefixtures("startup_event_force")