Skip to content

Commit

Permalink
Tweak pytest invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Jan 15, 2024
1 parent 83cbc32 commit d527c33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: pytest --cov=jobflow_remote --cov-report=xml --ignore tests/integration

- name: Integration tests
run: pytest --cov=jobflow_remote --cov-append --cov-report=xml tests/integration
run: pytest --cov=jobflow_remote --cov-append --cov-report=xml tests/integration -s

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
27 changes: 22 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@
from docker.models.containers import Container


def _get_free_port():
"""Returns a random free port."""
sock = socket.socket()
sock.bind(("", 0))
return sock.getsockname()[1]
def _get_free_port(upper_bound=50_000):
"""Returns a random free port, with an upper bound.
The upper bound is required as Docker does not have
permissions on high port numbers on some systems.
"""
port = upper_bound + 1
attempts = 0
max_attempts = 10
while port > upper_bound and attempts < max_attempts:
sock = socket.socket()
sock.bind(("", 0))
port = sock.getsockname()[1]
attempts += 1

if attempts == max_attempts:
raise RuntimeError(
f"Could not find a free port to use with the provided {upper_bound=}."
)

return port


def _get_random_name(length=6):
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_submit_flow(worker, job_controller):

from jobflow_remote import submit_flow
from jobflow_remote.jobs.runner import Runner
from jobflow_remote.jobs.state import FlowState, JobState
from jobflow_remote.testing import add

add_first = add(1, 5)
Expand All @@ -47,9 +48,9 @@ def test_submit_flow(worker, job_controller):
runner = Runner()
runner.run(ticks=10)

assert job_controller.count_jobs({}) == 2
assert len(job_controller.get_jobs({})) == 2
assert job_controller.count_flows({}) == 1
assert job_controller.count_jobs(state=JobState.COMPLETED) == 2
assert job_controller.count_flows(state=FlowState.COMPLETED) == 1


@pytest.mark.parametrize(
Expand All @@ -61,6 +62,7 @@ def test_submit_flow_with_dependencies(worker, job_controller):

from jobflow_remote import submit_flow
from jobflow_remote.jobs.runner import Runner
from jobflow_remote.jobs.state import FlowState, JobState
from jobflow_remote.testing import add, write_file

add_parent_1 = add(1, 1)
Expand All @@ -74,9 +76,9 @@ def test_submit_flow_with_dependencies(worker, job_controller):
runner = Runner()
runner.run(ticks=10)

assert job_controller.count_jobs({}) == 4
assert job_controller.count_jobs(state=JobState.COMPLETED) == 4
assert len(job_controller.get_jobs({})) == 4
assert job_controller.count_flows({}) == 1
assert job_controller.count_flows(state=FlowState.COMPLETED) == 1


@pytest.mark.parametrize(
Expand Down

0 comments on commit d527c33

Please sign in to comment.