Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/test_client_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion tests/test_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
1 change: 1 addition & 0 deletions tests/test_node_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down