@@ -75,7 +75,7 @@ async def slow_step(self, ev: StartEvent) -> StopEvent:
7575 return StopEvent (result = "Done" )
7676
7777 with pytest .raises (WorkflowTimeoutError ):
78- await WorkflowTestRunner (SlowWorkflow (timeout = 1 )).run ()
78+ await WorkflowTestRunner (SlowWorkflow (timeout = 0. 1 )).run ()
7979
8080
8181@pytest .mark .asyncio
@@ -442,21 +442,31 @@ async def step(self, ctx: Context, ev: StartEvent) -> StopEvent:
442442
443443@pytest .mark .asyncio
444444async def test_workflow_context_to_dict (workflow : Workflow ) -> None :
445- handler = workflow .run ()
446- ctx = handler .ctx
445+ ctx : Union [Context , None ] = None
446+ new_ctx : Union [Context , None ] = None
447+ try :
448+ handler = workflow .run ()
449+ ctx = handler .ctx
447450
448- ctx .send_event (EventWithName (name = "test" )) # type:ignore
451+ ctx .send_event (EventWithName (name = "test" )) # type:ignore
449452
450- # get the context dict
451- data = ctx .to_dict () # type:ignore
453+ # get the context dict
454+ data = ctx .to_dict () # type:ignore
452455
453- # finish workflow
454- await handler
456+ # finish workflow
457+ await handler
455458
456- new_ctx = Context .from_dict (workflow , data )
457- new_ctx ._init_broker (workflow )
458- assert new_ctx ._broker_run is not None
459- assert new_ctx ._broker_run ._state .queues ["start_step" ].get_nowait ().name == "test"
459+ new_ctx = Context .from_dict (workflow , data )
460+ new_ctx ._init_broker (workflow )
461+ assert new_ctx ._broker_run is not None
462+ assert (
463+ new_ctx ._broker_run ._state .queues ["start_step" ].get_nowait ().name == "test"
464+ )
465+ finally :
466+ if ctx is not None and ctx ._broker_run is not None :
467+ await ctx ._broker_run .shutdown ()
468+ if new_ctx is not None and new_ctx ._broker_run is not None :
469+ await new_ctx ._broker_run .shutdown ()
460470
461471
462472class HumanInTheLoopWorkflow (Workflow ):
0 commit comments