|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | import time |
| 9 | +import typing |
9 | 10 | from typing import Iterator, Tuple |
10 | 11 |
|
11 | 12 | from frequenz.api.microgrid import microgrid_pb2 |
@@ -67,6 +68,8 @@ def __init__( |
67 | 68 | self.battery_ids: list[int] = [] |
68 | 69 | self.meter_ids: list[int] = [4] |
69 | 70 |
|
| 71 | + self._actors: list[typing.Any] = [] |
| 72 | + |
70 | 73 | async def start(self) -> Tuple[Sender[ComponentMetricRequest], ChannelRegistry]: |
71 | 74 | """Start the MockServer, and the data source and resampling actors. |
72 | 75 |
|
@@ -248,20 +251,26 @@ async def _init_client_and_actors( |
248 | 251 | resampling_actor_request_channel.new_receiver() |
249 | 252 | ) |
250 | 253 |
|
251 | | - DataSourcingActor( |
252 | | - request_receiver=data_source_request_receiver, registry=channel_registry |
| 254 | + self._actors.append( |
| 255 | + DataSourcingActor( |
| 256 | + request_receiver=data_source_request_receiver, registry=channel_registry |
| 257 | + ) |
253 | 258 | ) |
254 | 259 |
|
255 | | - ComponentMetricsResamplingActor( |
256 | | - channel_registry=channel_registry, |
257 | | - data_sourcing_request_sender=data_source_request_sender, |
258 | | - resampling_request_receiver=resampling_actor_request_receiver, |
259 | | - config=ResamplerConfig(resampling_period_s=0.1), |
| 260 | + self._actors.append( |
| 261 | + ComponentMetricsResamplingActor( |
| 262 | + channel_registry=channel_registry, |
| 263 | + data_sourcing_request_sender=data_source_request_sender, |
| 264 | + resampling_request_receiver=resampling_actor_request_receiver, |
| 265 | + config=ResamplerConfig(resampling_period_s=0.1), |
| 266 | + ) |
260 | 267 | ) |
261 | 268 |
|
262 | 269 | return (resampling_actor_request_sender, channel_registry) |
263 | 270 |
|
264 | 271 | async def cleanup(self) -> None: |
265 | 272 | """Clean up after a test.""" |
| 273 | + for actor in self._actors: |
| 274 | + await actor._stop() # pylint: disable=protected-access |
266 | 275 | await self._server.graceful_shutdown() |
267 | 276 | microgrid._microgrid._MICROGRID = None # pylint: disable=protected-access |
0 commit comments