@@ -347,6 +347,46 @@ async def _run() -> tuple[list[int], list[tuple[int, int]]]:
347347 assert pairs == [(0 , 0 ), (1 , 2 ), (2 , 4 )]
348348
349349
350+ class TestMultiBarMode :
351+ def test_async_workers_see_their_task_bar (self ) -> None :
352+ from progressbar ._parallel import _common
353+
354+ seen : list [bool ] = []
355+
356+ async def _check (value : int ) -> int :
357+ seen .append (_common .current_task_bar () is not None )
358+ return value
359+
360+ async def _run () -> list [int ]:
361+ return await _async .amap (
362+ _check , range (3 ), bar = 'multi' , fd = io .StringIO ()
363+ )
364+
365+ assert asyncio .run (_run ()) == [0 , 1 , 2 ]
366+ assert seen == [True , True , True ]
367+
368+
369+ class TestExternalCancellation :
370+ def test_self_cancelling_task_surfaces (self ) -> None :
371+ async def _self_cancel (value : int ) -> int :
372+ if value == 1 :
373+ task = asyncio .current_task ()
374+ assert task is not None
375+ task .cancel ()
376+ await asyncio .sleep (1 )
377+ return value
378+
379+ async def _run () -> list [int ]:
380+ return await _async .amap (
381+ _self_cancel , range (3 ), concurrency = 1 , bar = False
382+ )
383+
384+ # A cancellation this run did not initiate must surface, never
385+ # silently drop the item.
386+ with pytest .raises (asyncio .CancelledError ):
387+ asyncio .run (_run ())
388+
389+
350390class TestCallStrategy :
351391 def test_detects_coroutine_function (self ) -> None :
352392 assert _async ._call_strategy (_async_double ) == 'async'
0 commit comments