fix(collect): handle login target close race
Tests / Python 3.11 / Windows (push) Has been cancelled
Tests / Python 3.11 / Windows (push) Has been cancelled
This commit is contained in:
@@ -35,6 +35,60 @@ class FakeBrowserCDP:
|
||||
|
||||
|
||||
class CdpTests(unittest.TestCase):
|
||||
def test_wait_target_closed_returns_when_target_disappears(self):
|
||||
targets = [
|
||||
[{"id": "target-closing", "type": "page"}],
|
||||
[],
|
||||
]
|
||||
with mock.patch("app.cdp.http_get", side_effect=targets) as http_get, mock.patch(
|
||||
"app.cdp.time.sleep"
|
||||
) as sleep:
|
||||
closed = cdp.wait_target_closed(
|
||||
"target-closing",
|
||||
host="127.0.0.1:9222",
|
||||
timeout=1.0,
|
||||
poll_interval=0.1,
|
||||
)
|
||||
|
||||
self.assertTrue(closed)
|
||||
sleep.assert_called_once_with(0.1)
|
||||
self.assertLessEqual(http_get.call_args_list[0].kwargs["timeout"], 1.0)
|
||||
|
||||
def test_wait_target_closed_stops_at_timeout(self):
|
||||
with mock.patch(
|
||||
"app.cdp.http_get",
|
||||
return_value=[{"id": "target-closing", "type": "page"}],
|
||||
) as http_get, mock.patch("app.cdp.time.sleep") as sleep:
|
||||
closed = cdp.wait_target_closed(
|
||||
"target-closing",
|
||||
host="127.0.0.1:9222",
|
||||
timeout=0,
|
||||
)
|
||||
|
||||
self.assertFalse(closed)
|
||||
sleep.assert_not_called()
|
||||
self.assertEqual(0.05, http_get.call_args.kwargs["timeout"])
|
||||
|
||||
def test_close_tab_and_wait_only_waits_after_close_request_succeeds(self):
|
||||
with mock.patch("app.cdp.close_tab", return_value=True) as close_tab, mock.patch(
|
||||
"app.cdp.wait_target_closed",
|
||||
return_value=True,
|
||||
) as wait_target_closed:
|
||||
closed = cdp.close_tab_and_wait(
|
||||
"target-closing",
|
||||
host="127.0.0.1:9222",
|
||||
timeout=1.5,
|
||||
)
|
||||
|
||||
self.assertTrue(closed)
|
||||
close_tab.assert_called_once_with("target-closing", host="127.0.0.1:9222")
|
||||
wait_target_closed.assert_called_once_with(
|
||||
"target-closing",
|
||||
host="127.0.0.1:9222",
|
||||
timeout=1.5,
|
||||
poll_interval=0.1,
|
||||
)
|
||||
|
||||
def test_create_tab_info_can_request_background_target(self):
|
||||
FakeBrowserCDP.sent = []
|
||||
FakeBrowserCDP.fail_first_create = False
|
||||
|
||||
Reference in New Issue
Block a user