Skip to content

Commit

Permalink
improve test_kraft
Browse files Browse the repository at this point in the history
  • Loading branch information
Iman Enami committed Dec 13, 2024
1 parent 275828b commit 5465d74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/events/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ def _remove_controller(
],
)
except Exception as e:
if "VoterNotFoundException" in getattr(e, "stderr"):
error_details = getattr(e, "stderr")
if "VoterNotFoundException" in error_details or "TimeoutException" in error_details:
# successful
return
raise e
Expand Down
22 changes: 14 additions & 8 deletions tests/integration/test_kraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class TestKRaft:
deployment_strat: str = os.environ.get("DEPLOYMENT", "multi")
controller_app: str = {"single": APP_NAME, "multi": CONTROLLER_APP}[deployment_strat]

async def _assert_listeners_accessible(self, ops_test: OpsTest, unit_num=0):
address = await get_address(ops_test=ops_test, app_name=APP_NAME, unit_num=0)
async def _assert_listeners_accessible(
self, ops_test: OpsTest, broker_unit_num=0, controller_unit_num=0
):
address = await get_address(ops_test=ops_test, app_name=APP_NAME, unit_num=broker_unit_num)
assert check_socket(
address, SECURITY_PROTOCOL_PORTS["SASL_PLAINTEXT", "SCRAM-SHA-512"].internal
) # Internal listener
Expand All @@ -47,7 +49,7 @@ async def _assert_listeners_accessible(self, ops_test: OpsTest, unit_num=0):
# Check controller socket
if self.controller_app != APP_NAME:
address = await get_address(
ops_test=ops_test, app_name=self.controller_app, unit_num=unit_num
ops_test=ops_test, app_name=self.controller_app, unit_num=controller_unit_num
)

assert check_socket(address, CONTROLLER_PORT)
Expand Down Expand Up @@ -132,7 +134,7 @@ async def test_integrate(self, ops_test: OpsTest):

@pytest.mark.abort_on_fail
async def test_listeners(self, ops_test: OpsTest):
await self._assert_listeners_accessible(ops_test, unit_num=0)
await self._assert_listeners_accessible(ops_test)

@pytest.mark.abort_on_fail
async def test_authorizer(self, ops_test: OpsTest):
Expand Down Expand Up @@ -193,10 +195,11 @@ async def test_leader_change(self, ops_test: OpsTest):
ops_test, f"{self.controller_app}/1", bootstrap_controller
)

# assert previous leader is removed
assert (offset + 0) not in unit_status
# assert new leader is elected
assert KRaftUnitStatus.LEADER in unit_status.values()
assert (
unit_status[offset + 1] == KRaftUnitStatus.LEADER
or unit_status[offset + 2] == KRaftUnitStatus.LEADER
)

# test cluster stability by adding a new controller
await ops_test.model.applications[self.controller_app].add_units(count=1)
Expand Down Expand Up @@ -241,4 +244,7 @@ async def test_scale_in(self, ops_test: OpsTest):
)

assert unit_status[offset + 3] == KRaftUnitStatus.LEADER
await self._assert_listeners_accessible(ops_test, unit_num=3)
broker_unit_num = 3 if self.controller_app == APP_NAME else 0
await self._assert_listeners_accessible(
ops_test, broker_unit_num=broker_unit_num, controller_unit_num=3
)

0 comments on commit 5465d74

Please sign in to comment.