Skip to content

Commit 1a670a8

Browse files
committed
Bypass loop time in *Pool tests with async_solipsism
This eliminates flakiness coming from running tests in slow or software-emulated VMs. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 99b25ec commit 1a670a8

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

tests/timeseries/_battery_pool/test_battery_pool_control_methods.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import datetime, timedelta, timezone
1010
from unittest.mock import AsyncMock, MagicMock
1111

12+
import async_solipsism
1213
import pytest
1314
from frequenz.channels import LatestValueCache, Sender
1415
from pytest_mock import MockerFixture
@@ -27,6 +28,12 @@
2728
from ..mock_microgrid import MockMicrogrid
2829

2930

31+
@pytest.fixture
32+
def event_loop_policy() -> async_solipsism.EventLoopPolicy:
33+
"""Event loop policy."""
34+
return async_solipsism.EventLoopPolicy()
35+
36+
3037
@dataclasses.dataclass(frozen=True)
3138
class Mocks:
3239
"""Mocks for the tests."""
@@ -89,11 +96,6 @@ async def _patch_battery_pool_status(
8996
If `battery_ids` is not None, the mock will always return `battery_ids`.
9097
Otherwise, it will return the requested batteries.
9198
"""
92-
mocker.patch.object(
93-
timeseries.battery_pool._methods, # pylint: disable=protected-access
94-
"WAIT_FOR_COMPONENT_DATA_SEC",
95-
0.1,
96-
)
9799
if battery_ids:
98100
mock = MagicMock(spec=ComponentPoolStatusTracker)
99101
mock.get_working_components.return_value = battery_ids

tests/timeseries/_ev_charger_pool/test_ev_charger_pool_control_methods.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime, timedelta, timezone
99
from unittest.mock import AsyncMock, MagicMock
1010

11+
import async_solipsism
1112
import pytest
1213
from frequenz.channels import Receiver
1314
from frequenz.client.microgrid import EVChargerCableState, EVChargerComponentState
@@ -38,6 +39,12 @@
3839
# pylint: disable=protected-access
3940

4041

42+
@pytest.fixture
43+
def event_loop_policy() -> async_solipsism.EventLoopPolicy:
44+
"""Event loop policy."""
45+
return async_solipsism.EventLoopPolicy()
46+
47+
4148
@pytest.fixture
4249
async def mocks(mocker: MockerFixture) -> typing.AsyncIterator[_Mocks]:
4350
"""Create the mocks."""

tests/timeseries/_pv_pool/test_pv_pool_control_methods.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime, timedelta, timezone
99
from unittest.mock import AsyncMock
1010

11+
import async_solipsism
1112
import pytest
1213
from frequenz.channels import Receiver
1314
from frequenz.client.microgrid import InverterComponentState
@@ -25,6 +26,12 @@
2526
from ..mock_microgrid import MockMicrogrid
2627

2728

29+
@pytest.fixture
30+
def event_loop_policy() -> async_solipsism.EventLoopPolicy:
31+
"""Event loop policy."""
32+
return async_solipsism.EventLoopPolicy()
33+
34+
2835
@pytest.fixture
2936
async def mocks(mocker: MockerFixture) -> typing.AsyncIterator[_Mocks]:
3037
"""Create the mocks."""

0 commit comments

Comments
 (0)