@@ -525,6 +525,31 @@ def test_live_block_for_close_timeout(
525525 live_client .terminate .assert_called_once () # type: ignore
526526
527527
528+ @pytest .mark .usefixtures ("mock_live_server" )
529+ def test_live_block_for_close_timeout_stream (
530+ live_client : client .Live ,
531+ monkeypatch : pytest .MonkeyPatch ,
532+ tmp_path : pathlib .Path ,
533+ ) -> None :
534+ """
535+ Test that block_for_close flushes user streams on timeout.
536+ """
537+ live_client .subscribe (
538+ dataset = Dataset .GLBX_MDP3 ,
539+ schema = Schema .MBO ,
540+ stype_in = SType .INSTRUMENT_ID ,
541+ symbols = "ALL_SYMBOLS" ,
542+ start = None ,
543+ )
544+ path = tmp_path / "test.dbn"
545+ stream = path .open ("wb" )
546+ monkeypatch .setattr (stream , "flush" , MagicMock ())
547+ live_client .add_stream (stream )
548+
549+ live_client .block_for_close (timeout = 0 )
550+ stream .flush .assert_called () # type: ignore [attr-defined]
551+
552+
528553@pytest .mark .usefixtures ("mock_live_server" )
529554async def test_live_wait_for_close (
530555 live_client : client .Live ,
@@ -571,6 +596,32 @@ async def test_live_wait_for_close_timeout(
571596 live_client .terminate .assert_called_once () # type: ignore
572597
573598
599+ @pytest .mark .usefixtures ("mock_live_server" )
600+ async def test_live_wait_for_close_timeout_stream (
601+ live_client : client .Live ,
602+ monkeypatch : pytest .MonkeyPatch ,
603+ tmp_path : pathlib .Path ,
604+ ) -> None :
605+ """
606+ Test that wait_for_close flushes user streams on timeout.
607+ """
608+ live_client .subscribe (
609+ dataset = Dataset .GLBX_MDP3 ,
610+ schema = Schema .MBO ,
611+ stype_in = SType .INSTRUMENT_ID ,
612+ symbols = "ALL_SYMBOLS" ,
613+ start = None ,
614+ )
615+
616+ path = tmp_path / "test.dbn"
617+ stream = path .open ("wb" )
618+ monkeypatch .setattr (stream , "flush" , MagicMock ())
619+ live_client .add_stream (stream )
620+
621+ await live_client .wait_for_close (timeout = 0 )
622+ stream .flush .assert_called () # type: ignore [attr-defined]
623+
624+
574625def test_live_add_callback (
575626 live_client : client .Live ,
576627) -> None :
@@ -615,6 +666,7 @@ def test_live_add_stream_invalid(
615666 with pytest .raises (ValueError ):
616667 live_client .add_stream (readable_file .open (mode = "rb" ))
617668
669+
618670def test_live_add_stream_path_directory (
619671 tmp_path : pathlib .Path ,
620672 live_client : client .Live ,
@@ -625,6 +677,7 @@ def test_live_add_stream_path_directory(
625677 with pytest .raises (OSError ):
626678 live_client .add_stream (tmp_path )
627679
680+
628681@pytest .mark .skipif (platform .system () == "Windows" , reason = "flaky on windows runner" )
629682async def test_live_async_iteration (
630683 live_client : client .Live ,
0 commit comments