Skip to content

Commit

Permalink
Mock resampler: Improve variable names
Browse files Browse the repository at this point in the history
Since the mock resampler uses a pair of channels, one to receive
samples to be (fakely) resampled (input) and one to send the (fakely)
resampmled samples (output), we should use clear names to identify both
otherwise is really hard to follow which is which when reading the code.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
  • Loading branch information
llucax committed Feb 14, 2024
1 parent 5df1db5 commit af3d816
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tests/timeseries/mock_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__( # pylint: disable=too-many-arguments
self._resampler_request_channel = Broadcast[ComponentMetricRequest](
"resampler-request"
)
self._basic_receivers: dict[str, list[Receiver[Sample[Quantity]]]] = {}
self._input_channels_receivers: dict[str, list[Receiver[Sample[Quantity]]]] = {}

def power_senders(
comp_ids: list[int],
Expand All @@ -58,7 +58,7 @@ def power_senders(
Sample[Quantity], name
).new_sender()
)
self._basic_receivers[name] = [
self._input_channels_receivers[name] = [
self._channel_registry.get_or_create(
Sample[Quantity], name
).new_receiver()
Expand All @@ -77,7 +77,7 @@ def frequency_senders(
Sample[Quantity], name
).new_sender()
)
self._basic_receivers[name] = [
self._input_channels_receivers[name] = [
self._channel_registry.get_or_create(
Sample[Quantity], name
).new_receiver(name)
Expand Down Expand Up @@ -119,19 +119,19 @@ def multi_phase_senders(
).new_sender(),
]
)
self._basic_receivers[p1_name] = [
self._input_channels_receivers[p1_name] = [
self._channel_registry.get_or_create(
Sample[Quantity], p1_name
).new_receiver()
for _ in range(namespaces)
]
self._basic_receivers[p2_name] = [
self._input_channels_receivers[p2_name] = [
self._channel_registry.get_or_create(
Sample[Quantity], p2_name
).new_receiver()
for _ in range(namespaces)
]
self._basic_receivers[p3_name] = [
self._input_channels_receivers[p3_name] = [
self._channel_registry.get_or_create(
Sample[Quantity], p3_name
).new_receiver()
Expand Down Expand Up @@ -222,15 +222,18 @@ async def _handle_resampling_requests(self) -> None:
name = request.get_channel_name()
if name in self._forward_tasks:
continue
basic_recv_name = f"{request.component_id}:{request.metric_id}"
recv = self._basic_receivers[basic_recv_name].pop()
assert recv is not None
input_chan_recv_name = f"{request.component_id}:{request.metric_id}"
input_chan_recv = self._input_channels_receivers[input_chan_recv_name].pop()
assert input_chan_recv is not None
output_chan_sender: Sender[Sample[Quantity]] = (
self._channel_registry.get_or_create(
Sample[Quantity], name
).new_sender()
)
task = asyncio.create_task(
self._channel_forward_messages(
recv,
self._channel_registry.get_or_create(
Sample[Quantity], name
).new_sender(),
input_chan_recv,
output_chan_sender,
),
name=name,
)
Expand Down

0 comments on commit af3d816

Please sign in to comment.