tests: the e2e stack watchdog holds the GIL (a Python thread), not faulthandler's dump_traceback_later, whose GIL-free copy of every thread's frames crashed the Windows part 3 worker

Five workers of the Windows part 3 of the e2e died, all on tests/test_fakeweb_p4_e2e.py::test_the_journey_leaves_every_page_only_once_its_noise_is_done, which runs 122-171 s with about 50 threads. tests/conftest.py armed faulthandler.dump_traceback_later(150 s, repeat=True) for every e2e test: a C thread that copies the frames of every thread WITHOUT the GIL (_Py_DumpTracebackThreads, documented "for debug purpose only ... after a segmentation fault, at fatal error") while the process keeps running and the other threads keep changing their frames. Two full dumps of a crashed worker show the process dead inside dump_frame, called from faulthandler_thread, reading a frame another thread was changing.

tests/_stack_watchdog.py is the same watchdog as a Python daemon thread: one per process, reused by every test; arm(nodeid, threshold_s, period_s, file) and cancel(); past the threshold, and then every period until cancelled, it writes "Timeout (h:mm:ss)!" and the frames of every thread (sys._current_frames(), holding the GIL, threads named from threading.enumerate()) to the same e2e-watchdog.log, in the format of faulthandler's dump; nothing to stdout or stderr; nothing after cancel() returns. Known limit, in the module: a thread that never releases the GIL keeps it from writing, which is pytest's faulthandler.enable() at the death of the process. tests/conftest.py calls it in place of dump_traceback_later and cancel_dump_traceback_later (setup, teardown, unconfigure).

Tests (all in the rows of wrapper.unit.all.linux and wrapper.unit.all.windows, min_tests 4061 -> 4116 and 4073 -> 4128, counted with the selector of the judge):
- tests/test_no_file_arms_a_gil_free_thread_dump.py: no .py of tests/, scripts/ or src/ calls faulthandler.dump_traceback_later, or dump_traceback with all_threads true or defaulted (ast, through any import form); pytest's faulthandler_timeout is set in no pyproject, pytest.ini, setup.cfg, tox.ini, conftest string, script string or workflow line (parsers, not text). Red on the conftest of 03425bb8, naming tests/conftest.py and the line, with how to fix and the rule; each form has its known-bad and its green twin. The only exclusion is norecursedirs of pyproject.toml.
- tests/test_the_stack_watchdog_writes_every_thread_after_its_threshold.py: in a child python, a blocked call gets the header and the stack of every thread, a test cancelled before its threshold leaves no dump, nothing is written after cancel (judged on the bytes of the file, waiting on the second test's first dump), the second test reuses the thread.
- tests/test_a_gil_free_thread_dump_kills_a_busy_process_and_the_stack_watchdog_does_not.py: 32 threads churning frames; dump_traceback_later at 1 ms ends the child with a crash status (red on the old mechanism), the new watchdog at a 1 ms period lets it run 6 s (60 times longer) and writes its dumps.
This commit is contained in:
feder-cr committed 2026-11-29 01:20:27 +01:00
1 parent 03425bb898
commit 8e342a1378
6 files changed
+670 -7

No files matched your search

+2 -2
View File
@@ -14,8 +14,8 @@
{"id": "wrapper.e2e.fakeweb", "giro": "G2", "os": ["linux", "windows"], "min_tests": 7, "exact": true, "tests": ["tests/test_fakeweb_p2_e2e.py", "tests/test_fakeweb_p4_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The fake web, offline: our browser on the hard pages (profile P2: a reused routed page reaches networkidle every time, also under a load of three other browsers; the other site is another process) and on the 17-step journey of a person (profile P4: every step as stock, and every page left only once its noise is done), each judged against what stock Firefox does, as tests/fakeweb/pages.json declares it. 7 = 3 + 4 (the last two: a `load` that takes 20 s is a step that succeeds, and a `load` that never comes ends in an error that names the wait and the page). Stock itself is held to that declaration, and compared with ours step by step, by scripts/run_fakeweb.py in .github/workflows/fakeweb.yml. Needs the candidate binary (STEALTHFOX_E2E_BINARY).", "stock_firefox": true, "extra_steps": ["fakeweb_profiles"]},
{"id": "wrapper.e2e.fontconfig", "giro": "G2", "os": ["linux"], "min_tests": 2, "exact": true, "tests": ["tests/test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e.py"], "marker": "e2e", "needs_root": false, "linux_only": "Fontconfig exists only on Linux: the parent of the engine shows <GRE>/fonts to it (FcConfigAppFontAddDir) to rebuild a font from a path and a face index. On Windows DirectWrite opens the file from its path, with no folder to scan and no cache to read, so this test has no Windows counterpart.", "note": "2 = (1) the stand-in that runs the engine under strace stays in the engine's place, as the core launches it (the leader of a process group of its own): a fake engine with a child, no browser; the process the launcher holds lives as long as the fake engine, and the group killed holds strace and the child (the stand-in that exec'd setsid forked and exited 0 at once: candidate 44161687675); (2) the warm launch of the parent reads the bundle from fontconfig's cache and does not scan it again (from firefox-66, engine_at_least). Two launches under strace with the same XDG_CACHE_HOME of the test, the first cold and the second warm: the cold parent opens every font file of <GRE>/fonts (the folder as the disk lists it) before any page and fontconfig writes its cache; the warm parent does not open every one of them, and it opens a *.cache-* file of fontconfig (a few files are opened to be used, so the verdict asks about the whole folder, as a scan does). Scan and drawing are told apart by position: only what the parent opens before the first page counts (the opens that draw are written as after_startup). Evidence in RUNNER_TEMP/invpw-evidence/fontconfig-cache: the interval and the number of opens of the bundle, the names of the files of the bundle each launch opened before the first page, the size of the cache file, the VmRSS of the parent after about:blank and after a page with every family, and a third launch with gfx.bundled-fonts.activate=0 (the behaviour before), which is evidence only. Needs strace on the runner: without it both are red, not skipped. No threshold."},
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 30, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference, and the box cut out of a screenshot (its pixels, a box outside the picture refused, written as a PNG and read back, two boxes told apart by a pixel that is named, the pixels that are not grey)."},
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 4061, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_generation_of_the_security_state_keeps_its_evidence.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_file_chooser_is_never_dropped_in_silence.py", "tests/test_a_frame_tap_needs_a_context_with_touch.py", "tests/test_a_handle_action_walks_like_a_selector_action.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_read_whose_probe_ran_out_is_the_callers_timeout.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_screenshot_refuses_what_would_touch_the_page.py", "tests/test_a_screenshot_sends_its_scale_to_the_engine.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_streamed_upload_is_staged_in_the_session.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_test_that_is_not_e2e_never_leaves_the_machine.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_ab_host.py", "tests/test_ab_host_aa_stable.py", "tests/test_ab_network.py", "tests/test_ab_network_turn_credential.py", "tests/test_ab_network_turn_deallocation.py", "tests/test_ab_network_webrtc_evidence.py", "tests/test_ab_oracle.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_element_handle_serves_every_method_of_the_client.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_host_gate_ab.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_linux_legs_read_no_mirror.py", "tests/test_ci_poison_host.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_windows_temp_is_on_d.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_action_is_pinned_by_commit_sha.py", "tests/test_every_argument_reaches_the_page_as_playwright_sends_it.py", "tests/test_every_held_request_of_the_journey_starts_after_the_load.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_every_windows_job_keeps_a_dump_of_a_crashing_python.py", "tests/test_every_wire_method_is_served_or_refused.py", "tests/test_expose_binding_refusal.py", "tests/test_fakeweb_p4_reportLine truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 4073, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_generation_of_the_security_state_keeps_its_evidence.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_file_chooser_is_never_dropped_in_silence.py", "tests/test_a_frame_tap_needs_a_context_with_touch.py", "tests/test_a_handle_action_walks_like_a_selector_action.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_read_whose_probe_ran_out_is_the_callers_timeout.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_screenshot_refuses_what_would_touch_the_page.py", "tests/test_a_screenshot_sends_its_scale_to_the_engine.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_streamed_upload_is_staged_in_the_session.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_test_that_is_not_e2e_never_leaves_the_machine.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_ab_host.py", "tests/test_ab_host_aa_stable.py", "tests/test_ab_network.py", "tests/test_ab_network_turn_credential.py", "tests/test_ab_network_turn_deallocation.py", "tests/test_ab_network_webrtc_evidence.py", "tests/test_ab_oracle.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_element_handle_serves_every_method_of_the_client.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_host_gate_ab.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_linux_legs_read_no_mirror.py", "tests/test_ci_poison_host.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_windows_temp_is_on_d.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_action_is_pinned_by_commit_sha.py", "tests/test_every_argument_reaches_the_page_as_playwright_sends_it.py", "tests/test_every_held_request_of_the_journey_starts_after_the_load.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_pytest_process_clears_the_gp_fault_error_box_on_windows.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_every_windows_job_keeps_a_dump_of_a_crashing_python.py", "tests/test_every_wire_method_is_served_orLine truncated
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 4116, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_generation_of_the_security_state_keeps_its_evidence.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_file_chooser_is_never_dropped_in_silence.py", "tests/test_a_frame_tap_needs_a_context_with_touch.py", "tests/test_a_gil_free_thread_dump_kills_a_busy_process_and_the_stack_watchdog_does_not.py", "tests/test_a_handle_action_walks_like_a_selector_action.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_read_whose_probe_ran_out_is_the_callers_timeout.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_screenshot_refuses_what_would_touch_the_page.py", "tests/test_a_screenshot_sends_its_scale_to_the_engine.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_streamed_upload_is_staged_in_the_session.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_test_that_is_not_e2e_never_leaves_the_machine.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_ab_host.py", "tests/test_ab_host_aa_stable.py", "tests/test_ab_network.py", "tests/test_ab_network_turn_credential.py", "tests/test_ab_network_turn_deallocation.py", "tests/test_ab_network_webrtc_evidence.py", "tests/test_ab_oracle.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_element_handle_serves_every_method_of_the_client.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_host_gate_ab.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_linux_legs_read_no_mirror.py", "tests/test_ci_poison_host.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_windows_temp_is_on_d.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_action_is_pinned_by_commit_sha.py", "tests/test_every_argument_reaches_the_page_as_playwright_sends_it.py", "tests/test_every_held_request_of_the_journey_starts_after_the_load.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_every_windows_job_keeps_a_dump_of_a_crashing_python.py", "tests/test_every_wire_method_isLine truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 4128, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_generation_of_the_security_state_keeps_its_evidence.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_file_chooser_is_never_dropped_in_silence.py", "tests/test_a_frame_tap_needs_a_context_with_touch.py", "tests/test_a_gil_free_thread_dump_kills_a_busy_process_and_the_stack_watchdog_does_not.py", "tests/test_a_handle_action_walks_like_a_selector_action.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_gives_the_core_its_engine_for_the_security_state.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_read_whose_probe_ran_out_is_the_callers_timeout.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_screenshot_refuses_what_would_touch_the_page.py", "tests/test_a_screenshot_sends_its_scale_to_the_engine.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_streamed_upload_is_staged_in_the_session.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_test_that_is_not_e2e_never_leaves_the_machine.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_ab_host.py", "tests/test_ab_host_aa_stable.py", "tests/test_ab_network.py", "tests/test_ab_network_turn_credential.py", "tests/test_ab_network_turn_deallocation.py", "tests/test_ab_network_webrtc_evidence.py", "tests/test_ab_oracle.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_element_handle_serves_every_method_of_the_client.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_host_gate_ab.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_lab_intermediates.py", "tests/test_ci_lab_security_state.py", "tests/test_ci_linux_legs_read_no_mirror.py", "tests/test_ci_poison_host.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_suite_run.py", "tests/test_ci_verdict.py", "tests/test_ci_windows_temp_is_on_d.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_ci_workflows_set_the_intermediates_list.py", "tests/test_ci_workflows_set_the_security_state.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_action_is_pinned_by_commit_sha.py", "tests/test_every_argument_reaches_the_page_as_playwright_sends_it.py", "tests/test_every_held_request_of_the_journey_starts_after_the_load.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_pytest_process_clears_the_gp_fault_error_box_on_windows.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_every_Line truncated
{"id": "wrapper.e2e.securitystate", "giro": "G2", "os": ["linux", "windows"], "min_tests": 4, "exact": true, "tests": ["tests/test_security_state_engine_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The security state the core declares, against the engine: the engine launched directly in its generate mode makes what it is given (the contract's result, security_state/ with the bytes of the full filter and of the delta, the core's own validation of it); a normal launch declares no pref of the mode and re-imports nothing; a certificate that Mozilla's CRLite test data say is revoked in a delta is refused at the first navigation (SEC_ERROR_REVOKED_CERTIFICATE) while a valid one loads, and the revoked one loads when the ready directory has no data; a ready directory with no or an empty security_state/ starts. Certificates made on the run (a fresh root trusted in cert9.db by the engine's own xpcshell, Mozilla's default test key as the key of CN=int), servers on loopback, no network. Red on firefox-67 (no generate mode).", "core_dumps": "invpw-cores"},
{"id": "wrapper.e2e.suite.linux.1", "giro": "G2", "os": ["linux"], "min_tests": 447, "exact": true, "tests": ["tests/test_a_closed_browser_leaves_the_others_alone_e2e.py", "tests/test_a_context_that_ends_leaves_no_process_e2e.py", "tests/test_a_cors_preflight_is_not_a_request_of_the_page_e2e.py", "tests/test_a_declared_webgl_extension_survives_its_use_e2e.py", "tests/test_a_granted_permission_is_the_one_the_page_asks_for_e2e.py", "tests/test_a_held_ice_port_blinds_the_loopback_checks_e2e.py", "tests/test_a_launch_without_a_session_gets_one_e2e.py", "tests/test_a_left_documents_body_is_evicted_e2e.py", "tests/test_a_mouse_click_makes_one_mousemove_on_its_point_e2e.py", "tests/test_a_page_over_ipv6_gathers_on_a_machine_declared_without_it_e2e.py", "tests/test_a_popup_is_reported_when_the_engine_says_it_is_ready_as_playwright_does_e2e.py", "tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py", "tests/test_a_screenshot_honours_its_scale_e2e.py", "tests/test_a_screenshot_refuses_what_would_touch_the_page_e2e.py", "tests/test_a_served_browser_answers_a_plain_client_e2e.py", "tests/test_a_tiny_download_on_a_served_browser_is_saved_e2e.py", "tests/test_a_turn_name_over_tcp_goes_through_the_proxy_of_the_context_e2e.py", "tests/test_accept_language_on_the_wire_e2e.py", "tests/test_browser_output_is_drained.py", "tests/test_click_rhythm.py", "tests/test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py", "tests/test_control_a_selects_all_in_a_field_e2e.py", "tests/test_cross_origin_iframe.py", "tests/test_declared_host_network_e2e.py", "tests/test_detectors_e2e.py", "tests/test_e2e.py", "tests/test_element_handle_actions.py", "tests/test_element_screenshot_e2e.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_file_chooser.py", "tests/test_fingerprint_surface.py", "tests/test_fission_frames_history_and_processes_e2e.py", "tests/test_fission_frames_workers_storage_and_special_frames_e2e.py", "tests/test_frames_outlive_the_back_forward_cache_e2e.py", "tests/test_goto_networkidle_after_spa_e2e.py", "tests/test_goto_script_redirect_e2e.py", "tests/test_hidden_display_linux.py", "tests/test_ice_names_by_the_context_proxy_e2e.py::test_the_ice_name_of_a_context_goes_by_the_proxy_of_that_context", "tests/test_ignore_https_errors_e2e.py", "tests/test_injected_node_surface.py", "tests/test_juggler_connection.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_navigation_across_processes_e2e.py", "tests/test_navigation_response.py", "tests/test_networkidle_reaches_the_client_e2e.py", "tests/test_oop_frame_element.py", "tests/test_oop_frame_geometry.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pointer_position.py", "tests/test_popups_reach_the_client_e2e.py", "tests/test_preload_newtab_turns_the_privileged_about_process_off_e2e.py", "tests/test_realness_behind_a_declared_exit_e2e.py", "tests/test_resolver_race_e2e.py", "tests/test_route_header_order_e2e.py", "tests/test_same_document_goto_e2e.py", "tests/test_screencast.py", "tests/test_screencast_stop_e2e.py", "tests/test_screenshot_looks_where_you_are.py", "tests/test_security_state_engine_e2e.py", "tests/test_service_worker.py", "tests/test_service_worker_controller_e2e.py", "tests/test_set_offline_e2e.py", "tests/test_shadow_trusted_input.py", "tests/test_strict_and_force.py", "tests/test_the_callers_code_is_not_counted_e2e.py", "tests/test_the_device_enumeration_takes_the_declared_time_e2e.py", "tests/test_the_engine_is_born_in_the_job_e2e.py::test_a_launch_scans_no_process_of_the_machine", "tests/test_the_engine_is_born_in_the_job_e2e.py::test_after_close_no_process_of_the_session_is_left", "tests/test_the_hosts_file_of_the_host_is_never_read_e2e.py", "tests/test_trial_does_not_act.py", "tests/test_turn_over_tcp_is_tried_for_real_e2e.py", "tests/test_ua_widget_not_selectable.py", "tests/test_voices_e2e.py", "tests/test_wait_for_function.py", "tests/test_webgl_draws_on_the_engine_s_own_gl_e2e.py", "tests/test_webgl_noise_active.py", "tests/test_webrtc_realness.py::test_a_gateway_that_is_far_away_still_gives_the_page_a_srflx_born_through_its_relay", "tests/test_webrtc_realness.py::test_a_gather_after_the_page_loaded_through_the_gateway_costs_only_the_road_to_the_server", "tests/test_webrtc_realness.py::test_a_host_with_ipv6_addresses_gathers_through_an_ipv4_relay", "tests/test_webrtc_realness.py::test_a_proxy_that_does_not_relay_udp_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_a_proxy_whose_relay_never_answers_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_a_proxy_whose_udp_leaves_from_another_address_gives_no_srflx_at_all", "tests/test_webrtc_realness.py::test_not_blocked_behind_tcp_only_socks", "tests/test_webrtc_realness.py::test_the_first_candidate_of_a_gather_does_not_wait_for_a_gateway_that_is_far_away", "tests/test_webrtc_realness.py::test_the_turn_over_tcp_of_a_context_goes_throuLine truncated
{"id": "wrapper.e2e.suite.linux.2", "giro": "G2", "os": ["linux"], "min_tests": 414, "exact": true, "tests": ["tests/test_a_click_waits_for_the_navigation_it_plans_e2e.py", "tests/test_a_context_init_script_runs_once_e2e.py", "tests/test_a_drag_keeps_its_buttons_pressed_e2e.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_goto_to_a_response_with_no_document_ends_e2e.py", "tests/test_a_keepalive_request_reaches_the_client_e2e.py", "tests/test_a_latin_letter_on_a_cyrillic_persona_e2e.py", "tests/test_a_page_cannot_probe_the_juggler_e2e.py", "tests/test_a_page_that_moves_on_e2e.py", "tests/test_a_pointer_event_is_handled_before_the_call_returns_e2e.py", "tests/test_a_request_says_what_it_is_e2e.py", "tests/test_a_worker_comes_back_with_its_page_from_the_cache_e2e.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_isolated_page_and_the_next_e2e.py", "tests/test_bypass_csp_e2e.py", "tests/test_caller_world_handles_e2e.py", "tests/test_canvas_reads_as_drawn.py", "tests/test_canvas_render_stealth.py", "tests/test_context_locale_e2e.py", "tests/test_context_proxy_only_resolves_by_doh_e2e.py", "tests/test_doh_through_the_proxy_e2e.py", "tests/test_doh_under_stress_e2e.py", "tests/test_download_is_intercepted_e2e.py", "tests/test_drag_motion.py", "tests/test_expose_binding_e2e.py", "tests/test_fakeweb_p4_e2e.py", "tests/test_fingerprint_consistency.py", "tests/test_fission_frames_dialogs_downloads_popups_e2e.py", "tests/test_fission_frames_route_and_bindings_e2e.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fission_iframe_crash_e2e.py", "tests/test_fission_strategy1_bench.py", "tests/test_goto_to_the_same_url_e2e.py", "tests/test_http3_through_the_proxy_e2e.py", "tests/test_input_is_born_before_the_page_sees_it_e2e.py", "tests/test_juggler_actions.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py::test_a_javascript_that_THROWS_arrives_as_an_error_not_as_None", "tests/test_juggler_injected.py::test_actionability_DISTINGUISHES_instead_of_always_saying_yes", "tests/test_juggler_injected.py::test_reads_that_make_no_sense_are_REJECTED", "tests/test_juggler_injected.py::test_states_DISCRIMINATE_instead_of_always_saying_true", "tests/test_juggler_injected.py::test_the_DOM_READING_group", "tests/test_juggler_injected.py::test_the_selector_engines_respond", "tests/test_juggler_injected.py::test_the_text_reads", "tests/test_juggler_lifecycle_e2e.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_long_session_e2e.py", "tests/test_mouse.py", "tests/test_mouse_events_keep_their_values_e2e.py", "tests/test_new_page_defaults.py", "tests/test_popup_destinations_e2e.py", "tests/test_popup_pages.py", "tests/test_proxy_http_auth_e2e.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_proxy_socks_auth_e2e.py", "tests/test_requestless_navigation.py", "tests/test_route_abort_code.py", "tests/test_route_e2e.py", "tests/test_route_post_data_e2e.py", "tests/test_route_sends_a_navigation_elsewhere_e2e.py", "tests/test_route_superseded_e2e.py", "tests/test_same_document_navigation.py", "tests/test_screenshot_of_text_returns_linux_e2e.py", "tests/test_scroll_into_view.py", "tests/test_scroll_only_if_needed_e2e.py", "tests/test_service_workers_blocked.py", "tests/test_set_input_files_payloads.py", "tests/test_software_compositing_is_declared_e2e.py", "tests/test_the_association_is_ready_when_the_peerconnection_is_born_e2e.py", "tests/test_the_callers_code_runs_once_e2e.py", "tests/test_the_close_returns_when_the_browser_has_exited_e2e.py", "tests/test_the_favicon_stays_out_of_sight_e2e.py", "tests/test_the_font_list_is_the_bundle_e2e.py", "tests/test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e.py", "tests/test_the_scheme_is_the_personas_e2e.py", "tests/test_the_whole_udp_chain_by_name_e2e.py::test_a_turn_srflx_by_name_arrives_through_the_relay_when_the_exit_of_the_lab_is_loopback", "tests/test_typing_a_character_without_a_key_e2e.py", "tests/test_wait_for_timeout.py", "tests/test_web_fonts_of_closed_contexts_e2e.py"], "marker": "e2e", "needs_root": false, "windows_twin": "wrapper.e2e.suite.windows.2", "note": "Part 2 of the whole e2e suite of the wrapper (every test that opens the browser: what e2e.yml runs on the published engine), on the engine under test, as two passes through scripts/ci_suite_run.py (4 browsers at once, then the wall_clock tests alone; no rerun). The files of the 2 rows of linux are the files of tests/ that tests/test_the_e2e_suite_is_accounted_for.py holds one by one: a file whole when every test of it is here, else its tests by name. Partition from the junits of runs 44942540063 and 44985244053, test time balanced (about 564 s of estimated wall time, 4 browsers). A new file is added by hand to a row of each system and the minimum of the row goes up by hand. Left out of every row, with the reason in the accounting test: the files and tests of wrapLine truncated
+111
View File
@@ -0,0 +1,111 @@
"""The stack watchdog of the e2e tests: a Python thread that writes the stack of every thread of the process, holding the GIL.
``tests/conftest.py`` arms it for each e2e test and cancels it in the teardown. Once the threshold of a test is passed, and then every period until the
test ends, it appends one dump to the file it was given: ``Timeout (h:mm:ss)!`` (the time since the arming) and then, for every thread, ``Thread 0x... (most
recent call first):`` and its frames as `` File "...", line N in name``. Two identical dumps mean a stuck test, two different ones a slow test.
Why a Python thread and not ``faulthandler.dump_traceback_later``: that watchdog is a C thread, and it copies the frames of every thread WITHOUT the GIL
(``_Py_DumpTracebackThreads``, which CPython documents as "for debug purpose only ... after a segmentation fault, at fatal error") while the other threads
keep running and keep changing their frames. On Windows two full dumps of a pytest worker show it dead inside ``dump_frame`` of ``faulthandler_thread``,
reading a frame another thread was freeing. This thread takes ``sys._current_frames()`` with the GIL held, so a frame it reads cannot change under it.
One thread per process, started by the first ``arm`` and reused by every later test. It writes nothing to stdout or stderr. After ``cancel`` returns, nothing
more is written for that test: the dump is written under the lock that ``cancel`` takes.
Known limit: a thread that holds the GIL and never releases it (a C call that does not let go) keeps this thread from running, so it cannot write. That case
is pytest's ``faulthandler.enable()``, which writes only when the process dies. The 420 s limit of the run (``--timeout-method thread``) still names the test.
"""
from __future__ import annotations
import sys
import threading
import time
def _clock(seconds: float) -> str:
whole = int(seconds)
return "%d:%02d:%02d" % (whole // 3600, whole % 3600 // 60, whole % 60)
class StackWatchdog:
def __init__(self) -> None:
self._cond = threading.Condition()
self._thread: threading.Thread | None = None
self._armed = False
self._file = None
self._started = 0.0
self._period = 0.0
self._due = 0.0
@property
def thread(self) -> threading.Thread | None:
"""The one thread of the process (None until the first ``arm``)."""
return self._thread
def arm(self, nodeid: str, threshold_s: float, period_s: float | None = None, file=None) -> None:
"""From ``threshold_s`` seconds on, and then every ``period_s`` (the threshold by default), write the stacks of all threads to ``file`` until ``cancel``."""
period = threshold_s if period_s is None else period_s
with self._cond:
self._file = file
self._started = time.monotonic()
self._period = max(period, 0.0005)
self._due = self._started + threshold_s
self._armed = True
try:
file.write("\n--- %s ---\n" % nodeid)
file.flush()
except Exception:
pass
if self._thread is None or not self._thread.is_alive():
self._thread = threading.Thread(target=self._run, name="invpw-stack-watchdog", daemon=True)
self._thread.start()
self._cond.notify_all()
def cancel(self) -> None:
"""Nothing more is written for the armed test once this returns: a dump in progress finishes first, because it is written under the same lock."""
with self._cond:
self._armed = False
self._file = None
self._cond.notify_all()
def _run(self) -> None:
with self._cond:
while True:
if not self._armed:
self._cond.wait()
continue
left = self._due - time.monotonic()
if left > 0:
# Waiting lets go of the lock, so that a cancel or a new arm is never kept out by a watchdog with a short period.
self._cond.wait(left)
continue
self._write_one_dump()
self._due = time.monotonic() + self._period
def _write_one_dump(self) -> None:
mine = threading.get_ident()
names = {t.ident: t.name for t in threading.enumerate()}
out = ["Timeout (%s)!\n" % _clock(time.monotonic() - self._started)]
for ident, frame in sys._current_frames().items():
if ident == mine:
continue
name = names.get(ident)
out.append("\nThread 0x%016x%s (most recent call first):\n" % (ident, " [%s]" % name if name else ""))
while frame is not None:
out.append(' File "%s", line %d in %s\n' % (frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name))
frame = frame.f_back
try:
self._file.write("".join(out))
self._file.flush()
except Exception:
# A watchdog that fails the suite over its OWN problem is worse than the defect it is watching for.
pass
_the_watchdog = StackWatchdog()
arm = _the_watchdog.arm
cancel = _the_watchdog.cancel
def the_thread() -> threading.Thread | None:
return _the_watchdog.thread
+5 -5
View File
@@ -1,4 +1,3 @@
import faulthandler
import http.server
import os
import random
@@ -10,6 +9,7 @@ from pathlib import Path
import pytest
import _stack_watchdog
from _servers import LocalServer
from _browser_census import _a_module_leaves_no_browser_open, _the_connections_a_test_made_are_closed_with_it # noqa: F401 (autouse)
@@ -95,13 +95,13 @@ def pytest_runtest_setup(item):
return
handle = _watchdog_open()
if handle is not None:
handle.write("\n--- %s ---\n" % item.nodeid)
faulthandler.dump_traceback_later(_WATCHDOG_S, repeat=True, file=handle)
# A Python thread that holds the GIL, not faulthandler.dump_traceback_later: that one copies the frames of every thread without the GIL and crashed a worker (tests/_stack_watchdog.py).
_stack_watchdog.arm(item.nodeid, _WATCHDOG_S, file=handle)
def pytest_runtest_teardown(item, nextitem):
if _watchdog_handle is not None:
faulthandler.cancel_dump_traceback_later()
_stack_watchdog.cancel()
@pytest.hookimpl(wrapper=True)
@@ -129,7 +129,7 @@ def pytest_collection_modifyitems(config, items):
def pytest_unconfigure(config):
global _watchdog_handle
if _watchdog_handle is not None:
faulthandler.cancel_dump_traceback_later()
_stack_watchdog.cancel()
_watchdog_handle.close()
_watchdog_handle = None
@@ -0,0 +1,126 @@
"""faulthandler's thread dump crashes a process whose threads churn frames, and the e2e stack watchdog does not: the hazard behind the Windows part 3 deaths.
Both halves run the same load in a child python: 32 threads that call a recursive function and start and join a short thread, over and over, so that frames
are created and freed all the time, while a watchdog dumps the stacks of every thread every millisecond.
* The old mechanism, ``faulthandler.dump_traceback_later(0.001, repeat=True)``, copies the frames of every thread without the GIL. The child must die with a
crash status (a signal on Linux, an NT status such as 0xC0000005 on Windows), never end well and never end with an exception (status 1). It dies in under 100 ms
on CPython 3.11 and 3.12, and the child gets 60 s before the test says that this Python did not show the hazard. This is the proof that the hazard is real.
* The new watchdog (``tests/_stack_watchdog.py``) at a period of 1 ms, on the same load, must let the child run for SURVIVAL_S = 6 s (sixty times what the old
one lasts) and end with status 0, with the file holding a dump of the threads for at least 20 dumps.
The child sets itself up not to leave a trace of its crash: on Windows the error mode without the crash box (no Windows Error Reporting dialog and no dump
in the LocalDumps folder of a job that keeps them), on Linux a core limit of 0.
"""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
import pytest
pytestmark = pytest.mark.unit
TESTS = Path(__file__).resolve().parent
SURVIVAL_S = 6.0
THREADS = 32
HAZARD_DEADLINE_S = 60.0
CHILD = '''
import json, os, sys, threading, time
mode, seconds, threads, tests_dir, log_path = sys.argv[1], float(sys.argv[2]), int(sys.argv[3]), sys.argv[4], sys.argv[5]
if sys.platform == "win32":
import ctypes
ctypes.windll.kernel32.SetErrorMode(0x8003)
else:
import resource
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
sys.path.insert(0, tests_dir)
stop = threading.Event()
def deep(n):
if n == 0:
return sum(i for i in range(5))
return deep(n - 1) + 1
def churn():
while not stop.is_set():
deep(30)
t = threading.Thread(target=deep, args=(10,))
t.start()
t.join()
class Sink:
"""Counts the dumps and keeps the first megabyte of them in the file: a dump every millisecond would fill a disk."""
def __init__(self, path):
self.file = open(path, "w", encoding="utf-8")
self.kept = 0
self.dumps = 0
def write(self, text):
self.dumps += text.count("Timeout (")
if self.kept < 1000000:
self.kept += self.file.write(text)
def flush(self):
self.file.flush()
if mode == "old":
import faulthandler
faulthandler.dump_traceback_later(0.001, repeat=True, file=open(os.devnull, "w"))
else:
import _stack_watchdog as dog
sink = Sink(log_path)
dog.arm("stress", 0.001, 0.001, file=sink)
workers = [threading.Thread(target=churn, daemon=True) for _ in range(threads)]
for w in workers:
w.start()
time.sleep(seconds)
stop.set()
if mode == "old":
faulthandler.cancel_dump_traceback_later()
else:
dog.cancel()
for w in workers:
w.join()
print(json.dumps({"survived": True, "dumps": 0 if mode == "old" else sink.dumps}))
'''
def _run(tmp_path: Path, mode: str, seconds: float, timeout: float):
script = tmp_path / ("child_%s.py" % mode)
script.write_text(CHILD, encoding="utf-8")
log = tmp_path / "dumps.log"
done = subprocess.run([sys.executable, str(script), mode, str(seconds), str(THREADS), str(TESTS), str(log)], capture_output=True, text=True, timeout=timeout)
return done, log
def _crashed(returncode: int) -> bool:
"""A signal on POSIX (negative), an NT status (0xC0000005 and the like, from 0x80000000) on Windows. An exception of Python is 1, a good end is 0."""
return returncode < 0 or returncode >= 0x80000000
def test_the_dump_of_faulthandler_kills_a_process_that_churns_frames(tmp_path):
done, _ = _run(tmp_path, "old", HAZARD_DEADLINE_S, HAZARD_DEADLINE_S + 60)
assert _crashed(done.returncode), (
"faulthandler.dump_traceback_later(0.001, repeat=True) did not crash the child on this Python (%s, status %s): the GIL-free copy of the frames "
"did not show on %d threads in %d s. stdout %r, stderr %r" % (sys.version.split()[0], done.returncode, THREADS, HAZARD_DEADLINE_S, done.stdout[-200:], done.stderr[-500:]))
def test_the_stack_watchdog_survives_the_same_load_for_sixty_times_as_long(tmp_path):
done, log = _run(tmp_path, "new", SURVIVAL_S, SURVIVAL_S + 120)
assert done.returncode == 0, "the child ended with status %s after at most %s s, stderr %r" % (done.returncode, SURVIVAL_S, done.stderr[-800:])
result = json.loads(done.stdout)
assert result["survived"] and result["dumps"] >= 20, result
text = log.read_text(encoding="utf-8", errors="replace")
assert "Timeout (" in text and "Thread 0x" in text and "in churn" in text
@@ -0,0 +1,304 @@
"""No code of this repository arms a thread dump that copies the frames of every thread without the GIL: that dump crashes a live process.
``faulthandler.dump_traceback_later`` (and pytest's ``faulthandler_timeout``, which arms it), and ``faulthandler.dump_traceback`` with ``all_threads`` true or
defaulted, walk the frames of every thread with ``_Py_DumpTracebackThreads``: CPython documents it as "for debug purpose only ... after a segmentation fault, at
fatal error". Its watchdog is a C thread that does not hold the GIL while the process keeps running, so it reads a frame another thread is freeing. The Windows
part 3 of the e2e lost five workers that way, inside ``dump_frame`` of ``faulthandler_thread`` (two full dumps), all on the one test that runs 2 minutes with about 50
threads. The e2e stack watchdog is ``tests/_stack_watchdog.py``, a Python thread that writes ``sys._current_frames()`` holding the GIL.
What is read, as code and never as text: the ``.py`` files of ``tests/``, ``scripts/`` and ``src/`` with ``ast`` (a call, through ``import faulthandler``, an alias
of it, or ``from faulthandler import ...``; a comment or a string that names the function is not a call); ``pyproject.toml`` with a TOML parser, and
``pytest.ini``, ``setup.cfg`` and ``tox.ini`` with ``configparser``, for the key ``faulthandler_timeout`` and for it inside ``addopts``; the strings of the
``conftest.py`` files and of ``scripts/`` (an ``addopts`` or a ``-o`` argument); the lines of ``.github/workflows/*.yml`` that are not comments.
Vendored code is excluded only where the repository already has an exclusion list: ``norecursedirs`` of ``[tool.pytest.ini_options]`` in ``pyproject.toml``
(``playwright-upstream``, the vendored suite of Playwright, which is not in the tree). The Playwright client vendored in ``src/invisible_playwright/_pw`` has no
list and is read like the rest.
Known-bad inputs, each on a tree in ``tmp_path``: the two lines of ``tests/conftest.py`` of 03425bb8, every form of the call, every place the timeout can be set.
Each has its positive next to it: ``dump_traceback(all_threads=False)``, ``faulthandler.enable(all_threads=True)`` (a dump at the death of the process), a comment
and a string that name the function, a workflow comment, an excluded folder. The green case is the state of the repository.
"""
from __future__ import annotations
import ast
import configparser
import re
import tomllib
from pathlib import Path
import pytest
pytestmark = pytest.mark.unit
ROOT = Path(__file__).resolve().parent.parent
CODE_DIRS = ("tests", "scripts", "src")
ALWAYS_SKIPPED = {"__pycache__"}
TIMEOUT_NAME = re.compile(r"faulthandler[-_]timeout")
RULE = ("the rule: no thread dump that reads the frames of every thread without the GIL (faulthandler.dump_traceback_later, pytest's faulthandler_timeout, "
"dump_traceback with all_threads) may be armed in a live process, because it crashed the Windows part 3 worker")
FIX = "use tests/_stack_watchdog.py (arm and cancel), a Python thread that writes sys._current_frames() holding the GIL"
def _say(where: str, what: str) -> str:
return "%s: %s. How to fix: %s. %s" % (where, what, FIX, RULE)
def _pyproject(root: Path) -> dict:
path = root / "pyproject.toml"
return tomllib.loads(path.read_text(encoding="utf-8")) if path.is_file() else {}
def _pytest_tables(data: dict) -> list:
tool = data.get("tool", {}).get("pytest", {})
return [t for t in (tool.get("ini_options"), tool if "ini_options" not in tool else None) if isinstance(t, dict)]
def excluded_dirs(root: Path) -> set:
"""The only exclusion list the repository has: norecursedirs of pytest, in pyproject.toml."""
out = set(ALWAYS_SKIPPED)
for table in _pytest_tables(_pyproject(root)):
out.update(table.get("norecursedirs", []))
return out
def python_files(root: Path, folders=CODE_DIRS):
skipped = excluded_dirs(root)
for folder in folders:
base = root / folder
if not base.is_dir():
continue
for path in sorted(base.rglob("*.py")):
if not skipped.intersection(path.relative_to(root).parts):
yield path
def _faulthandler_names(tree: ast.AST):
modules, functions = set(), {}
for node in ast.walk(tree):
if isinstance(node, ast.Import):
modules.update(a.asname or a.name for a in node.names if a.name == "faulthandler")
elif isinstance(node, ast.ImportFrom) and node.module == "faulthandler":
functions.update({a.asname or a.name: a.name for a in node.names})
return modules, functions
def _all_threads_is_false(call: ast.Call) -> bool:
"""dump_traceback(file, all_threads): only a literal False is proof that one thread is dumped."""
for keyword in call.keywords:
if keyword.arg == "all_threads":
return isinstance(keyword.value, ast.Constant) and keyword.value.value is False
return len(call.args) >= 2 and isinstance(call.args[1], ast.Constant) and call.args[1].value is False
def calls_in_source(source: str) -> list:
"""(line, text) of every call to faulthandler.dump_traceback_later and of faulthandler.dump_traceback that dumps every thread."""
tree = ast.parse(source)
modules, functions = _faulthandler_names(tree)
found = []
for node in ast.walk(tree):
if not isinstance(node, ast.Call):
continue
func = node.func
if isinstance(func, ast.Attribute) and isinstance(func.value, ast.Name) and func.value.id in modules:
name = func.attr
elif isinstance(func, ast.Name) and func.id in functions:
name = functions[func.id]
else:
continue
if name == "dump_traceback_later":
found.append((node.lineno, "faulthandler.dump_traceback_later is armed"))
elif name == "dump_traceback" and not _all_threads_is_false(node):
found.append((node.lineno, "faulthandler.dump_traceback dumps every thread (all_threads is true or defaulted)"))
return found
def timeout_strings_in_source(source: str) -> list:
"""(line, text) of every string of the code that names pytest's faulthandler_timeout (an addopts, a -o argument, a command line)."""
return [(n.lineno, "a string names pytest's faulthandler_timeout: %r" % n.value[:80])
for n in ast.walk(ast.parse(source)) if isinstance(n, ast.Constant) and isinstance(n.value, str) and TIMEOUT_NAME.search(n.value)]
def python_problems(root: Path) -> list:
out = []
for path in python_files(root):
where = path.relative_to(root).as_posix()
try:
source = path.read_text(encoding="utf-8")
found = calls_in_source(source)
except (SyntaxError, UnicodeDecodeError, ValueError) as error:
out.append(_say(where, "the file cannot be read as Python (%s), so it cannot be shown free of the dump" % error))
continue
out += [_say("%s:%d" % (where, line), what) for line, what in found]
return out
def string_problems(root: Path) -> list:
"""The strings of every conftest.py and of scripts/ that name faulthandler_timeout."""
paths = [p for p in python_files(root, ("tests",)) if p.name == "conftest.py"] + list(python_files(root, ("scripts",)))
out = []
for path in paths:
try:
found = timeout_strings_in_source(path.read_text(encoding="utf-8"))
except (SyntaxError, UnicodeDecodeError, ValueError):
continue # python_problems already says that a file cannot be read
out += [_say("%s:%d" % (path.relative_to(root).as_posix(), line), what) for line, what in found]
return out
def _value_names_timeout(value) -> bool:
return bool(TIMEOUT_NAME.search(" ".join(value) if isinstance(value, list) else str(value)))
def config_problems(root: Path) -> list:
out = []
for table in _pytest_tables(_pyproject(root)):
if "faulthandler_timeout" in table:
out.append(_say("pyproject.toml [tool.pytest.ini_options]", "faulthandler_timeout is set (it arms dump_traceback_later for every test)"))
if _value_names_timeout(table.get("addopts", "")):
out.append(_say("pyproject.toml [tool.pytest.ini_options] addopts", "addopts names faulthandler_timeout"))
for name, section in (("pytest.ini", "pytest"), ("setup.cfg", "tool:pytest"), ("tox.ini", "pytest")):
path = root / name
if not path.is_file():
continue
parser = configparser.ConfigParser(interpolation=None)
parser.read_string(path.read_text(encoding="utf-8"))
if parser.has_option(section, "faulthandler_timeout"):
out.append(_say("%s [%s]" % (name, section), "faulthandler_timeout is set (it arms dump_traceback_later for every test)"))
if parser.has_option(section, "addopts") and _value_names_timeout(parser.get(section, "addopts")):
out.append(_say("%s [%s] addopts" % (name, section), "addopts names faulthandler_timeout"))
return out
def workflow_problems(root: Path) -> list:
out = []
folder = root / ".github" / "workflows"
for path in sorted(folder.glob("*.yml")) if folder.is_dir() else []:
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
code = re.split(r"(?:^|\s)#", line, maxsplit=1)[0]
if TIMEOUT_NAME.search(code):
out.append(_say("%s:%d" % (path.relative_to(root).as_posix(), number), "the workflow sets pytest's faulthandler_timeout: %s" % code.strip()[:100]))
return out
def problems(root: Path) -> list:
return python_problems(root) + string_problems(root) + config_problems(root) + workflow_problems(root)
def _tree(tmp_path: Path, files: dict) -> Path:
for name, text in files.items():
path = tmp_path / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text, encoding="utf-8")
return tmp_path
def test_no_file_of_the_repository_arms_a_gil_free_thread_dump():
found = problems(ROOT)
assert not found, "\n".join(found)
# The two lines of tests/conftest.py of 03425bb8, which the e2e of the Windows part 3 ran.
OLD_CONFTEST = '''import faulthandler
def pytest_runtest_setup(item):
handle = open("w.log", "a")
faulthandler.dump_traceback_later(150.0, repeat=True, file=handle)
def pytest_runtest_teardown(item, nextitem):
faulthandler.cancel_dump_traceback_later()
'''
def test_the_conftest_of_03425bb8_is_red_and_names_the_file_and_the_line(tmp_path):
found = problems(_tree(tmp_path, {"tests/conftest.py": OLD_CONFTEST}))
assert len(found) == 1
assert found[0].startswith("tests/conftest.py:6: faulthandler.dump_traceback_later is armed. How to fix: use tests/_stack_watchdog.py")
assert "crashed the Windows part 3 worker" in found[0]
@pytest.mark.parametrize("source, line", [
("import faulthandler\nfaulthandler.dump_traceback_later(1)\n", 2),
("import faulthandler as fh\nfh.dump_traceback_later(1, repeat=True)\n", 2),
("from faulthandler import dump_traceback_later\ndump_traceback_later(1)\n", 2),
("from faulthandler import dump_traceback_later as arm\ndef f():\n arm(1)\n", 3),
("import faulthandler\nfaulthandler.dump_traceback()\n", 2),
("import faulthandler\nfaulthandler.dump_traceback(all_threads=True)\n", 2),
("import faulthandler, sys\nfaulthandler.dump_traceback(sys.stderr, True)\n", 2),
("import faulthandler\nfaulthandler.dump_traceback(all_threads=some_flag)\n", 2),
("from faulthandler import dump_traceback\ndump_traceback(None)\n", 2),
])
@pytest.mark.parametrize("folder", ["tests", "scripts", "src/pkg"])
def test_every_form_of_the_call_is_red_in_every_folder(tmp_path, folder, source, line):
found = python_problems(_tree(tmp_path, {folder + "/a.py": source}))
assert [f.split(":")[0:2] for f in found] == [["%s/a.py" % folder, str(line)]]
def test_a_file_that_cannot_be_parsed_is_red_and_not_skipped(tmp_path):
found = python_problems(_tree(tmp_path, {"scripts/broken.py": "def (:\n"}))
assert len(found) == 1 and found[0].startswith("scripts/broken.py: the file cannot be read as Python")
@pytest.mark.parametrize("source", [
"import faulthandler\nfaulthandler.dump_traceback(all_threads=False)\n",
"import faulthandler, sys\nfaulthandler.dump_traceback(sys.stderr, False)\n",
"import faulthandler\nfaulthandler.enable(all_threads=True)\nfaulthandler.cancel_dump_traceback_later()\n",
"# faulthandler.dump_traceback_later(1)\nx = 'faulthandler.dump_traceback_later(1)'\n",
'"""faulthandler.dump_traceback_later(1)"""\n',
"def dump_traceback_later(x):\n return x\ndump_traceback_later(1)\n",
"class faulthandler:\n def dump_traceback_later(self): ...\nfaulthandler().dump_traceback_later()\n",
])
def test_the_uses_that_do_not_crash_a_live_process_are_green(tmp_path, source):
assert python_problems(_tree(tmp_path, {"tests/a.py": source})) == []
def test_a_folder_in_norecursedirs_is_the_only_one_left_out(tmp_path):
call = "import faulthandler\nfaulthandler.dump_traceback_later(1)\n"
pyproject = '[tool.pytest.ini_options]\nnorecursedirs = ["playwright-upstream"]\n'
root = _tree(tmp_path, {"pyproject.toml": pyproject, "tests/playwright-upstream/a.py": call, "tests/vendor/b.py": call})
assert [f.split(":")[0] for f in python_problems(root)] == ["tests/vendor/b.py"]
assert excluded_dirs(root) == {"__pycache__", "playwright-upstream"}
@pytest.mark.parametrize("pyproject", [
'[tool.pytest.ini_options]\nfaulthandler_timeout = 300\n',
'[tool.pytest.ini_options]\naddopts = "-m unit -o faulthandler_timeout=300"\n',
'[tool.pytest.ini_options]\naddopts = ["-m", "unit", "--faulthandler-timeout=300"]\n',
'[tool.pytest]\nfaulthandler_timeout = 300\n',
])
def test_the_timeout_of_pytest_in_pyproject_is_red(tmp_path, pyproject):
found = config_problems(_tree(tmp_path, {"pyproject.toml": pyproject}))
assert len(found) == 1 and found[0].startswith("pyproject.toml [tool.pytest")
@pytest.mark.parametrize("name, section", [("pytest.ini", "pytest"), ("setup.cfg", "tool:pytest"), ("tox.ini", "pytest")])
def test_the_timeout_of_pytest_in_an_ini_file_is_red(tmp_path, name, section):
found = config_problems(_tree(tmp_path, {name: "[%s]\nfaulthandler_timeout = 300\n" % section}))
assert len(found) == 1 and found[0].startswith("%s [%s]" % (name, section))
found = config_problems(_tree(tmp_path / "b", {name: "[%s]\naddopts = -x --faulthandler-timeout=9\n" % section}))
assert len(found) == 1 and found[0].startswith("%s [%s] addopts" % (name, section))
def test_a_config_with_no_timeout_is_green(tmp_path):
files = {"pyproject.toml": '[tool.pytest.ini_options]\naddopts = "-m unit"\ntimeout = 420\n', "pytest.ini": "[pytest]\naddopts = -x\n",
"tox.ini": "[tox]\nenvlist = a\n[testenv]\ncommands = pytest -o faulthandler_timeout=3\n", "setup.cfg": "[flake8]\nmax-line-length = 9\n"}
assert config_problems(_tree(tmp_path, files)) == []
def test_a_conftest_and_a_script_that_name_the_timeout_in_a_string_are_red(tmp_path):
root = _tree(tmp_path, {
"tests/conftest.py": "def pytest_configure(config):\n config.addinivalue_line('addopts', '--faulthandler-timeout=9')\n",
"scripts/run.py": "ARGS = ['pytest', '-o', 'faulthandler_timeout=9']\n",
"tests/test_a.py": "ARGS = ['-o', 'faulthandler_timeout=9']\n",
})
assert [f.split(":")[0:2] for f in string_problems(root)] == [["tests/conftest.py", "2"], ["scripts/run.py", "1"]]
def test_a_workflow_that_sets_the_timeout_is_red_and_a_comment_is_not(tmp_path):
root = _tree(tmp_path, {".github/workflows/a.yml": "jobs:\n t:\n steps:\n # pytest -o faulthandler_timeout=9 is what not to do\n"
" - run: pytest -o faulthandler_timeout=300 tests # not this\n"
" - run: pytest --faulthandler-timeout 5\n"
" - run: pytest tests # --faulthandler-timeout 5\n"})
assert [f.split(":")[0:2] for f in workflow_problems(root)] == [[".github/workflows/a.yml", "5"], [".github/workflows/a.yml", "6"]]
@@ -0,0 +1,122 @@
"""The e2e stack watchdog (``tests/_stack_watchdog.py``) writes the stacks of every thread once the threshold of a test is passed, and nothing after the cancel.
It runs in a child python, so that no thread of this pytest session is touched and the file is the only thing read. The child arms the watchdog for a test, parks
in a function named ``the_blocked_call_of_the_test`` until the file holds two dumps (it waits on the file, with a deadline of 90 s that is only a guard against a
hang), cancels, and arms a second test, whose first dump it waits for. What the parent checks, on the file and on the exit of the child:
* the dump has the header ``Timeout (h:mm:ss)!`` and, for the threads, ``Thread 0x... (most recent call first):`` with the frames, the blocked function's name
among them and the name of a parked thread (from ``threading.enumerate()``): the shape that whoever reads ``e2e-watchdog.log`` reads;
* a test that is cancelled before its threshold leaves its ``--- nodeid ---`` line and no dump;
* once ``cancel`` returned, nothing more is written for that test: the bytes of the file at that moment are the same after the second test's first dump, and
everything after them belongs to the second test (the second dump arriving is what shows the watchdog was running, so no fixed wait decides the verdict);
* the second test reuses the same thread, and the process has only one watchdog thread;
* nothing is written to stdout or stderr but the child's own result line.
"""
from __future__ import annotations
import json
import re
import subprocess
import sys
from pathlib import Path
import pytest
pytestmark = pytest.mark.unit
TESTS = Path(__file__).resolve().parent
CHILD = '''
import json, os, sys, threading, time
sys.path.insert(0, sys.argv[1])
import _stack_watchdog as dog
path = sys.argv[2]
log = open(path, "a", buffering=1, encoding="utf-8")
def raw():
with open(path, "rb") as handle:
return handle.read()
def waiting_for(condition, what):
end = time.monotonic() + 90
while not condition():
if time.monotonic() > end:
raise SystemExit("timed out waiting for " + what)
time.sleep(0.01)
def the_blocked_call_of_the_test():
waiting_for(lambda: raw().count(b"Timeout (") >= 2, "two dumps of the first test")
parked = threading.Thread(target=threading.Event().wait, name="a-parked-thread", daemon=True)
parked.start()
dog.arm("tests/test_a.py::too_fast_to_be_watched", 3600, file=log)
dog.cancel()
dog.arm("tests/test_a.py::first", 0.1, file=log)
first_thread = dog.the_thread().ident
the_blocked_call_of_the_test()
dog.cancel()
size_at_cancel = os.path.getsize(path)
dog.arm("tests/test_a.py::second", 0.1, file=log)
second_thread = dog.the_thread().ident
waiting_for(lambda: raw()[size_at_cancel:].count(b"Timeout (") >= 1, "the first dump of the second test")
dog.cancel()
watchdogs = [t for t in threading.enumerate() if t.name == "invpw-stack-watchdog"]
print(json.dumps({"size_at_cancel": size_at_cancel, "first": first_thread, "second": second_thread, "watchdog_threads": len(watchdogs)}))
'''
@pytest.fixture(scope="module")
def run(tmp_path_factory):
folder = tmp_path_factory.mktemp("stack_watchdog")
script, log = folder / "child.py", folder / "e2e-watchdog.log"
script.write_text(CHILD, encoding="utf-8")
done = subprocess.run([sys.executable, str(script), str(TESTS), str(log)], capture_output=True, text=True, timeout=180)
return done, log.read_bytes() if log.exists() else b""
def test_the_child_ends_well_and_writes_to_neither_stdout_nor_stderr(run):
done, _ = run
assert done.returncode == 0, done.stderr[-1500:]
assert done.stderr == ""
assert len(done.stdout.splitlines()) == 1 and json.loads(done.stdout)["watchdog_threads"] == 1, done.stdout
def _lines(raw: bytes) -> str:
return raw.decode("utf-8").replace("\r\n", "\n")
def test_a_blocked_test_gets_the_stack_of_every_thread_with_the_header_of_the_log(run):
_, raw = run
first = _lines(raw).split("--- tests/test_a.py::first ---")[1].split("--- tests/test_a.py::second ---")[0]
assert re.search(r"^Timeout \(\d+:\d{2}:\d{2}\)!$", first, re.MULTILINE), first[:600]
assert re.search(r"^Thread 0x[0-9a-f]{16} \[a-parked-thread\] \(most recent call first\):$", first, re.MULTILINE), first[:1500]
assert re.search(r'^ File ".*child\.py", line \d+ in the_blocked_call_of_the_test$', first, re.MULTILINE), first[:1500]
assert first.count("Timeout (") >= 2
def test_a_test_cancelled_before_its_threshold_leaves_its_line_and_no_dump(run):
_, raw = run
unwatched = _lines(raw).split("--- tests/test_a.py::too_fast_to_be_watched ---")[1].split("--- tests/test_a.py::first ---")[0]
assert "Timeout (" not in unwatched and "Thread 0x" not in unwatched
def test_nothing_is_written_for_a_test_after_its_cancel(run):
done, raw = run
size = json.loads(done.stdout)["size_at_cancel"]
before, after = _lines(raw[:size]), _lines(raw[size:])
assert after.startswith("\n--- tests/test_a.py::second ---\n"), after[:300]
assert "--- tests/test_a.py::first ---" not in after and "--- tests/test_a.py::second ---" not in before
def test_the_second_test_reuses_the_thread_of_the_first(run):
done, _ = run
result = json.loads(done.stdout)
assert result["first"] == result["second"] and result["watchdog_threads"] == 1