diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bce9977 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 + with: + python-version: "3.12" + - run: pip install -e ".[dev]" + - run: ruff check . + - run: ruff format --check . + - run: pytest -q diff --git a/tests/test_client_create.py b/tests/test_client_create.py index 38bec93..f81fc01 100644 --- a/tests/test_client_create.py +++ b/tests/test_client_create.py @@ -156,3 +156,13 @@ def test_rollback_hard_failure_is_reported_as_failed(): assert error.states == {A: PRESENT, B: ABSENT, C: ABSENT} assert error.cluster_consistent is False assert str(error).endswith("rollback: http://b restored, http://a failed") + + +def test_context_manager_closes_only_the_http_client_it_created(): + shared = httpx.Client(transport=httpx.MockTransport(lambda request: httpx.Response(404))) + with ClusterClient(["node1"], client=shared): + pass + assert not shared.is_closed + with ClusterClient(["node1"]) as owned: + pass + assert owned._client.is_closed diff --git a/tests/test_drive.py b/tests/test_drive.py index 847eab8..2d93387 100644 --- a/tests/test_drive.py +++ b/tests/test_drive.py @@ -4,7 +4,7 @@ import pytest from api_consumer.node_api import NodeState -from api_consumer.retry import drive_node_to +from api_consumer.retry import RetryPolicy, drive_node_to from fake_cluster import FakeCluster, recording_policy PRESENT, ABSENT, UNKNOWN = NodeState.PRESENT, NodeState.ABSENT, NodeState.UNKNOWN @@ -101,3 +101,9 @@ def test_delete_timeout_then_get_absent_is_success_with_no_second_delete(): result, calls, _ = drive(ABSENT, mutations=[TIMEOUT], gets=[404]) assert (result.reached, result.state) == (True, ABSENT) assert calls == ["DELETE", "GET"] + + +def test_a_policy_without_attempts_is_rejected(): + node = FakeCluster().node("node1") + with pytest.raises(ValueError): + drive_node_to(node, "g1", PRESENT, RetryPolicy(max_attempts=0, sleep=lambda _: None)) diff --git a/tests/test_node_api.py b/tests/test_node_api.py index b758286..da3acc9 100644 --- a/tests/test_node_api.py +++ b/tests/test_node_api.py @@ -64,6 +64,7 @@ def test_get_404_means_absent(): respond(200, {"groupId": "other"}), respond(200, {"x": 1}), respond(200, [1]), + lambda request: httpx.Response(200, text="not json"), respond(204), respond(403), ],