Skip to content

Commit 3f7cbbf

Browse files
committed
Fix stream() not working with base-client 0.11
And fix test to catch it next time. Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent b04df36 commit 3f7cbbf

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/frequenz/client/dispatch/_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ def _get_stream(
242242
) -> GrpcStreamBroadcaster[StreamMicrogridDispatchesResponse, DispatchEvent]:
243243
"""Get an instance to the streaming helper."""
244244
broadcaster = self._streams.get(microgrid_id)
245-
# pylint: disable=protected-access
246-
if broadcaster is not None and broadcaster._channel.is_closed:
247-
# pylint: enable=protected-access
245+
if broadcaster is not None and not broadcaster.is_running:
248246
del self._streams[microgrid_id]
249247
broadcaster = None
250248
if broadcaster is None:

tests/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ async def test_dispatch_stream(client: FakeClient, sample: Dispatch) -> None:
309309

310310
stream = client.stream(microgrid_id)
311311

312+
# Call function again to test behavior if stream already exists
313+
_ = client.stream(microgrid_id)
314+
312315
async def expect(dispatch: Dispatch, event: Event) -> None:
313316
message = await stream.receive()
314317
assert message.dispatch == dispatch

0 commit comments

Comments
 (0)