File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/frequenz/client/dispatch/test Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 88import dataclasses
99from dataclasses import dataclass , replace
1010from datetime import datetime , timezone
11+ from random import shuffle
1112
1213import grpc
1314import grpc .aio
@@ -45,6 +46,9 @@ class FakeService:
4546 _last_id : int = 0
4647 """Last used dispatch id."""
4748
49+ _shuffle_after_create : bool = False
50+ """Whether to shuffle the dispatches after creating them."""
51+
4852 # pylint: disable=invalid-name
4953 async def ListMicrogridDispatches (
5054 self , request : PBDispatchListRequest
@@ -116,6 +120,9 @@ async def CreateMicrogridDispatch(
116120 update_time = datetime .now (tz = timezone .utc ),
117121 )
118122 )
123+ if self ._shuffle_after_create :
124+ shuffle (self .dispatches )
125+
119126 return Empty ()
120127
121128 async def UpdateMicrogridDispatch (
Original file line number Diff line number Diff line change @@ -17,10 +17,15 @@ class FakeClient(Client):
1717 This client uses a fake service to simulate the dispatch api.
1818 """
1919
20- def __init__ (self ) -> None :
21- """Initialize the mock client."""
20+ def __init__ (self , shuffle_after_create : bool = False ) -> None :
21+ """Initialize the mock client.
22+
23+ Args:
24+ shuffle_after_create: Whether to shuffle the dispatches after creating them.
25+ """
2226 super ().__init__ (MagicMock (), "mock" )
2327 self ._stub = FakeService () # type: ignore
28+ self ._service ._shuffle_after_create = shuffle_after_create
2429
2530 @property
2631 def dispatches (self ) -> list [Dispatch ]:
You can’t perform that action at this time.
0 commit comments