@@ -304,26 +304,39 @@ def test_expect_response_should_not_hang_when_predicate_throws(page: Page) -> No
304304 raise Exception ("Oops!" )
305305
306306
307- def test_expect_response_should_not_switch_to_stale_greenlet_when_cancelled (
307+ def test_expect_event_should_not_switch_to_stale_greenlet (
308308 page : Page , server : Server
309309) -> None :
310310 # Mimics frameworks like pytest-twisted that run the test body in a separate
311311 # greenlet which stays alive (suspended) after handing control back.
312312 main = greenlet .getcurrent ()
313- resumed : List [bool ] = []
314313
315- def body () -> None :
314+ def expect_not_resumed (action : Callable [[], None ]) -> None :
315+ resumed : List [bool ] = []
316+
317+ def body () -> None :
318+ action ()
319+ main .switch ()
320+ resumed .append (True )
321+ main .switch ()
322+
323+ greenlet (body ).switch ()
324+ # Pumps the dispatcher, which runs the done callbacks of the futures.
325+ page .goto (server .EMPTY_PAGE )
326+ assert resumed == []
327+
328+ def cancel_wait () -> None :
316329 with pytest .raises (Exception , match = "Oops!" ):
317330 with page .expect_response ("**/*" ):
318331 raise Exception ("Oops!" )
319- main .switch ()
320- resumed .append (True )
321- main .switch ()
322332
323- greenlet (body ).switch ()
324- # Pumps the dispatcher, which runs the cancelled future's done callbacks.
325- page .goto (server .EMPTY_PAGE )
326- assert resumed == []
333+ def wait_for_done_future () -> None :
334+ with page .expect_console_message () as message_info :
335+ page .evaluate ("console.log('hello')" )
336+ assert message_info .value .text == "hello"
337+
338+ expect_not_resumed (cancel_wait )
339+ expect_not_resumed (wait_for_done_future )
327340
328341
329342def test_expect_response_should_use_context_timeout (
0 commit comments