Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for save db artifact #246

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c43ba7
Testing continue on error and failure in workflow.
davidwaroquiers Jan 17, 2025
a1b957a
Test...
davidwaroquiers Jan 17, 2025
d522c77
Test
davidwaroquiers Jan 17, 2025
932e2ce
Test
davidwaroquiers Jan 17, 2025
8e5b0a3
Test
davidwaroquiers Jan 17, 2025
e8e3d5e
Test
davidwaroquiers Jan 17, 2025
6ebea48
Test
davidwaroquiers Jan 17, 2025
3892a31
Testing as an action.
davidwaroquiers Jan 20, 2025
dd539ee
Fix action.
davidwaroquiers Jan 20, 2025
7fa672f
test action.
davidwaroquiers Jan 20, 2025
5aee809
Removed commented sections in github workflow.
davidwaroquiers Jan 20, 2025
7c0260a
Merge branch 'develop' into dw/test_failure_dbdump
davidwaroquiers Jan 21, 2025
65c9d1e
Added get_flows to jobcontroller. Failed tests were showing a
davidwaroquiers Jan 23, 2025
7b7681d
Merge branch 'develop' into dw/test_failure_dbdump
davidwaroquiers Jan 23, 2025
24250c9
Added explicit failing test.
davidwaroquiers Jan 24, 2025
6f0da1f
Added upload db dump artifact.
davidwaroquiers Jan 24, 2025
93d3a32
Removed conftest in tests/github_ci
davidwaroquiers Jan 24, 2025
170c816
Added back same conftest in tests/github_ci as the one in tests/db
davidwaroquiers Jan 24, 2025
a486079
Testing download artifact.
davidwaroquiers Jan 24, 2025
c9f6100
Testing...
davidwaroquiers Jan 24, 2025
3651212
Fixing action...
davidwaroquiers Jan 24, 2025
c6c2731
Testing ...
davidwaroquiers Jan 24, 2025
c61c16d
Testing ...
davidwaroquiers Jan 24, 2025
953207f
Testing ...
davidwaroquiers Jan 24, 2025
b1e3302
Updates to save artifact: directory now includes test directory tree.
davidwaroquiers Jan 28, 2025
215d212
Deal with test parameters.
davidwaroquiers Jan 28, 2025
9b5e443
Adding parametrized test.
davidwaroquiers Jan 28, 2025
3647a85
Added one more failing test.
davidwaroquiers Jan 29, 2025
7ef5d0e
Merge branch 'develop' into dw/test_failure_dbdump
davidwaroquiers Jan 30, 2025
ae239da
Fixed typo in CHANGELOG.
davidwaroquiers Jan 30, 2025
922d5fb
Almost there.
davidwaroquiers Jan 30, 2025
6f063e5
Fix.
davidwaroquiers Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/actions/save-db-test-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Testing save db artifact"
description: "This action ensures that the save db artifact works properly"
inputs:
python-version:
description: 'Python version used'
required: true
runs:
using: "composite"
steps:
- name: Testing the save db artifact in case a test fails
id: failure
run: |
pytest tests/github_ci
shell: bash
continue-on-error: true

# Ensure previous test indeed failed (it continues on error but also continues on success ...)
- name: Make sure the previous step has failed
if: ${{ steps.failure.outcome == 'success' }}
run: |
echo "The previous step with an explicit failure should have failed while it succeeded"
exit 1
shell: bash

- name: Upload DB dump
if: ${{ steps.failure.outcome == 'failure' }}
uses: actions/upload-artifact@v4
id: artifact-upload-test
with:
name: db_dump_${{ inputs.python-version }}
path: test_folder
if-no-files-found: error

# This should check that a dump has been created in the github workspace, check its content (?)
# and then remove it
- name: Check the dump of the db
run: |
echo "Checking db dump"
shell: bash

- name: Download and inspect the artifact
if: ${{ steps.failure.outcome == 'failure' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Downloading artifact directly using gh CLI..."
gh api --method GET \
-H "Accept: application/vnd.github+json" \
repos/matgenix/jobflow-remote/actions/artifacts/${{ steps.artifact-upload-test.outputs.artifact-id }}/zip > artifact.zip

echo "Unzipping artifact..."
unzip artifact.zip -d unzipped_artifact

echo "Checking unzipped artifact contents..."
python tests/github_ci/check_artifact.py unzipped_artifact
shell: bash

- name: Clean up local files
run: |
echo "Removing files"
rm artifact.zip
rm -r unzipped_artifact
shell: bash
137 changes: 71 additions & 66 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,71 +97,76 @@ jobs:
pip install -r requirements/requirements.txt
pip install .[tests]

- name: Unit tests
run: |
COVERAGE_FILE=.coverage-unit \
pytest \
--pytest-durations-min=1 \
--cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
tests/unit

- name: Database tests
run: |
COVERAGE_FILE=.coverage-db \
pytest \
--pytest-durations-min=1 \
--cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
tests/db

- name: Full integration tests
run: |
COVERAGE_FILE=.coverage-integration \
pytest \
--pytest-durations-min=1 \
--cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
tests/integration

- name: Codecov upload
if: matrix.python-version == '3.12'
uses: ./.github/actions/codecov-upload-action
- name: Testing save db artifact
uses: ./.github/actions/save-db-test-action
with:
codecov-token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload DB dump
if: failure()
uses: actions/upload-artifact@v4
with:
name: db_dump_${{ matrix.python-version }}
path: test_folder

docs:
name: Build documentation
runs-on: ubuntu-latest
python-version: ${{ matrix.python-version }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install docs dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
# Required to generate rst files from markdown
sudo apt install pandoc
pip install -r requirements/requirements.txt
pip install .[docs]

- name: Build Sphinx docs
working-directory: doc
run: |
# cannot use sphinx build directly as the makefile handles generation
# of some rst files
make html
# - name: Unit tests
# run: |
# COVERAGE_FILE=.coverage-unit \
# pytest \
# --pytest-durations-min=1 \
# --cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
# tests/unit
#
# - name: Database tests
# run: |
# COVERAGE_FILE=.coverage-db \
# pytest \
# --pytest-durations-min=1 \
# --cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
# tests/db
#
# - name: Full integration tests
# run: |
# COVERAGE_FILE=.coverage-integration \
# pytest \
# --pytest-durations-min=1 \
# --cov=jobflow_remote --cov-report= --cov-config=pyproject.toml \
# tests/integration
#
# - name: Codecov upload
# if: matrix.python-version == '3.12'
# uses: ./.github/actions/codecov-upload-action
# with:
# codecov-token: ${{ secrets.CODECOV_TOKEN }}
#
# - name: Upload DB dump
# if: failure()
# uses: actions/upload-artifact@v4
# with:
# name: db_dump_${{ matrix.python-version }}
# path: test_folder
#
# docs:
# name: Build documentation
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# submodules: true
# fetch-depth: 0
#
# - name: Set up Python 3.11
# uses: actions/setup-python@v5
# with:
# python-version: '3.11'
#
# - name: Install docs dependencies
# run: |
# python -m pip install -U pip
# pip install -U setuptools wheel
# # Required to generate rst files from markdown
# sudo apt install pandoc
# pip install -r requirements/requirements.txt
# pip install .[docs]
#
# - name: Build Sphinx docs
# working-directory: doc
# run: |
# # cannot use sphinx build directly as the makefile handles generation
# # of some rst files
# make html
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- how to limit number of jobs [\#195](https://github.com/Matgenix/jobflow-remote/issues/195)
- non-unique uuids as a problem in jobflow-remote [\#193](https://github.com/Matgenix/jobflow-remote/issues/193)
- Set `projects_folder` via env var [\#188](https://github.com/Matgenix/jobflow-remote/issues/188)
- Support for heterogenous computing resources? [\#184](https://github.com/Matgenix/jobflow-remote/issues/184)
- Support for heterogeneous computing resources? [\#184](https://github.com/Matgenix/jobflow-remote/issues/184)
- Jobflow remote logo [\#178](https://github.com/Matgenix/jobflow-remote/issues/178)
- How could I use SGE for job submission? [\#159](https://github.com/Matgenix/jobflow-remote/issues/159)
- Check there is not already a runner running [\#140](https://github.com/Matgenix/jobflow-remote/issues/140)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ docstring-code-format = true
"__init__.py" = ["F401"]
"**/tests/*" = ["INP001", "S101"]
"**/testing/*" = ["S101"]
"tests/github_ci/check_artifact.py" = ["T203"]

[tool.mypy]
ignore_missing_imports = true
Expand Down Expand Up @@ -163,6 +164,7 @@ filterwarnings = [
addopts = [
"--import-mode=importlib",
]
norecursedirs = ["tests/github_ci"]

[tool.coverage.run]
parallel = true
Expand Down
3 changes: 3 additions & 0 deletions src/jobflow_remote/jobs/jobcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,9 @@ def get_job_doc(
def get_jobs(self, query, projection: list | dict | None = None):
return list(self.jobs.find(query, projection=projection))

def get_flows(self, query, projection: list | dict | None = None):
return list(self.flows.find(query, projection=projection))

def count_jobs(
self,
query: dict | None = None,
Expand Down
38 changes: 25 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@


@pytest.fixture(scope="session")
def test_dir():
module_dir = Path(__file__).resolve().parent
test_dir = module_dir / "test_data"
return test_dir.resolve()
def tests_dir():
return Path(__file__).resolve().parent.resolve()


@pytest.fixture(scope="session")
def test_data_dir(tests_dir):
return tests_dir / "test_data"


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -146,15 +149,15 @@ def reset_logging_config():


@pytest.fixture(scope="session")
def upgrade_test_dir(test_dir):
def upgrade_test_dir(test_data_dir):
"""
Path to the test data directory used for upgrade tests.

Returns:
Path: Path to the test data directory used for upgrade tests.
"""

return test_dir / "upgrade"
return test_data_dir / "upgrade"


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
Expand All @@ -172,7 +175,7 @@ def pytest_runtest_makereport(item, call):
def shared_test_out_dir(tmp_path_factory):
"""
Fixture to lazily create a shared temporary directory to store the dump
of MongoDB for failed tests and move them to store as an artifact is
of MongoDB for failed tests and move them to store as an artifact if
running on github.
"""
import os
Expand All @@ -197,7 +200,7 @@ def get_or_create():


@pytest.fixture()
def job_controller(random_project_name, request, shared_test_out_dir):
def job_controller(random_project_name, request, shared_test_out_dir, tests_dir):
"""Yields a jobcontroller instance for the test suite that also sets up the
jobstore, resetting it after every test.
"""
Expand All @@ -212,12 +215,21 @@ def job_controller(random_project_name, request, shared_test_out_dir):
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
target_dir = shared_test_out_dir()

# use the test name (including parameters) as a target folder
test_name = request.node.name
sanitized_test_name = "".join(c if c.isalnum() else "_" for c in test_name)

test_dump_dir = target_dir / sanitized_test_name
# use the test directory tree + test name (including parameters) as a target folder
test_filepath = request.node.path
testpath_relative_to_tests_dir = test_filepath.relative_to(tests_dir)
test_name = request.node.originalname

test_dump_dir = target_dir / testpath_relative_to_tests_dir / test_name
params = None
if hasattr(request.node, "callspec"):
params_id = request.node.callspec.id
sanitized_params_id = "".join(c if c.isalnum() else "_" for c in params_id)
test_dump_dir = test_dump_dir / sanitized_params_id
params = request.node.callspec.params
test_dump_dir.mkdir(parents=True, exist_ok=True)
test_info = {"name": request.node.name, "params": params}
dumpfn(test_info, test_dump_dir / "test_info.json", indent=2)

# don't use the backup to create indented json files for easier access

Expand Down
Loading
Loading