File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
src/frequenz/client/dispatch Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff line change 1010from functools import partial
1111
1212import grpc
13+ import pytest
1314from pytest import raises
1415
1516from frequenz .client .dispatch .test .client import FakeClient , to_create_params
@@ -302,13 +303,20 @@ async def test_delete_dispatch_fail(client: FakeClient) -> None:
302303 await client .delete (microgrid_id = 1 , dispatch_id = 1 )
303304
304305
305- async def test_dispatch_stream (client : FakeClient , sample : Dispatch ) -> None :
306+ @pytest .mark .parametrize ("call_twice" , [True , False ])
307+ async def test_dispatch_stream (
308+ client : FakeClient , sample : Dispatch , call_twice : bool
309+ ) -> None :
306310 """Test dispatching a stream of dispatches."""
307311 microgrid_id = random .randint (1 , 100 )
308312 dispatches = [sample , sample , sample ]
309313
310314 stream = client .stream (microgrid_id )
311315
316+ if call_twice :
317+ # Call function again to test behavior if stream already exists
318+ _ = client .stream (microgrid_id )
319+
312320 async def expect (dispatch : Dispatch , event : Event ) -> None :
313321 message = await stream .receive ()
314322 assert message .dispatch == dispatch
You can’t perform that action at this time.
0 commit comments