Skip to content

Commit 1d33be7

Browse files
committed
Ensure ComponentPoolStatusTracker is stopped properly
If the test raised an exception in the middle of the test, the `ComponentPoolStatusTracker` was not stopped, which caused the `ComponentPoolStatusTracker` to keep running and entering a restart loop when the asyncio event loop was closed. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 52b8380 commit 1d33be7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tests/microgrid/power_distributing/_component_status/test_battery_pool_status.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Tests for BatteryPoolStatus."""
44

55
import asyncio
6+
from contextlib import AsyncExitStack
67
from datetime import timedelta
78

89
from frequenz.channels import Broadcast
@@ -37,7 +38,8 @@ async def test_batteries_status(self, mocker: MockerFixture) -> None:
3738
mock_microgrid = MockMicrogrid(grid_meter=True, mocker=mocker)
3839
mock_microgrid.add_batteries(3)
3940

40-
async with mock_microgrid:
41+
async with AsyncExitStack() as stack:
42+
await stack.enter_async_context(mock_microgrid)
4143
batteries = {
4244
battery.component_id
4345
for battery in mock_microgrid.mock_client.component_graph.components(
@@ -55,6 +57,7 @@ async def test_batteries_status(self, mocker: MockerFixture) -> None:
5557
max_blocking_duration=timedelta(seconds=30),
5658
component_status_tracker_type=BatteryStatusTracker,
5759
)
60+
stack.push_async_callback(batteries_status.stop)
5861
await asyncio.sleep(0.1)
5962

6063
expected_working: set[ComponentId] = set()
@@ -123,5 +126,3 @@ async def test_batteries_status(self, mocker: MockerFixture) -> None:
123126
ComponentId(9),
124127
ComponentId(19),
125128
}
126-
127-
await batteries_status.stop()

0 commit comments

Comments
 (0)