tests: a failed far-away gather says the control connection's times, the core's UDP measurement, the stalls of the process and the runner's load (+25 tests)

Both far-away gathers (the one with an rtt and the one after the page loaded) kept no record of where the time went when the core's UDP
measurement ends unmeasured. The watch now also starts, with the gateway's own record: a read of the control connections' times (connect,
greeting, authentication, ASSOCIATE asked and answered, and the longest wait inside the gateway for an answer); a handler on the core's
logger invisible_core._udp_exit at DEBUG, set and removed around the test, next to marks of the launch; a daemon thread that beats every
50 ms and keeps the gaps over 200 ms; and the runner's CPU and load every 0.5 s with psutil. They go in the saved evidence (cells.json,
stall-witness, runner-load, core-udp-exit-log) and as four short lines in the failure message (a note of the exception when the failure is
not an assertion). The second test now keeps evidence too. No budget, threshold or retry changes; every recorder takes one dict per record,
never raises into the test or a server, and a unit file makes each fail on purpose (clock, load source, log record, records list) and makes a
real stall of the whole process (a GIL-holding call) to see the witness catch it.
This commit is contained in:
feder-cr committed 2026-11-22 15:30:30 +01:00
1 parent b58e078035
commit fd7d8a64aa
4 files changed
+822 -27

No files matched your search

+2 -2
View File
@@ -14,7 +14,7 @@
{"id": "wrapper.e2e.fakeweb", "giro": "G2", "os": ["linux", "windows"], "min_tests": 4, "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), each judged against what stock Firefox does, as tests/fakeweb/pages.json declares it. 4 = 3 + 1. 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)."},
{"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": 2236, "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_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.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_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.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_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_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.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_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_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_moving_page_model.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", Line truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2237, "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_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.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_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.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_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_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.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_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_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_moving_page_model.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.Line truncated
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2261, "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_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.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_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.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_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_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.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_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_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_moving_page_model.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", Line truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2262, "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_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.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_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.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_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_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.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_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_expose_binding_refusal.py", "tests/test_fakeweb_p4_report.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_moving_page_model.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_legacy_in_the_wrapper.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.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)."}
]
+359
View File
@@ -0,0 +1,359 @@
"""What a failed far-away gather says about the machine and the core's own measurement (the recorders of ``_Watch`` in tests/test_webrtc_realness.py).
The gateway of these tests simulates distance with sleeps and timers inside the process of pytest, which also runs the core's UDP measurement.
When the gather fails the question is where the time went: in the gateway's own answers, in a stall of the whole worker process, or in a
runner with no CPU left. Three recorders answer it, each kept as a list of records the evidence saves (``FailureEvidence.note_records``) and
each said in a few lines of the failure message:
* the times of every control connection of the gateway (connect, greeting, authentication, ASSOCIATE asked and answered), read from the
records the watch already makes, and how long the gateway sat on an answer;
* the records of the core's logger ``invisible_core._udp_exit`` at DEBUG (the outcome of its UDP measurement), set and removed around the test,
next to the marks the test makes (the launch that runs the measurement starts and returns);
* a witness of the whole process (a daemon thread that beats every 50 ms and records the gaps over 200 ms) and the runner's CPU load,
sampled every 0.5 s.
Nothing here changes an assertion, a wait, a deadline or a measurement: a recorder only listens, never raises into the test or into a server,
and takes every record as ONE dict (no keyword that can collide with a field of the data).
"""
from __future__ import annotations
import logging
import threading
import time
#: The logger of the core whose DEBUG records say how its UDP measurement ended (``invisible_core/_udp_exit.py``: ``log = getLogger(__name__)``).
UDP_EXIT_LOGGER = "invisible_core._udp_exit"
#: The beat of the witness and the gap it calls a stall, in seconds.
BEAT_S, STALL_S = 0.05, 0.2
#: How often the runner's load is sampled, in seconds.
LOAD_EVERY_S = 0.5
#: The most control connections and stalls said in the message (the evidence has all of them).
MESSAGE_CONNECTIONS, MESSAGE_STALLS = 3, 4
class Records:
"""A list of records for ``FailureEvidence.note_records`` (``lock``, ``records``). ``add`` never raises: it is called from threads of the test
and, through the watch, from the gateway's own."""
def __init__(self):
self.lock = threading.Lock()
self.records = []
def add(self, record):
try:
record = dict(record)
record.setdefault("t", round(time.time(), 4))
with self.lock:
self.records.append(record)
except Exception as problem: # noqa: BLE001 - recorded, never raised
try:
with self.lock:
self.records.append({"origin": "probe", "event": "a record could not be kept", "error": repr(problem)})
except Exception: # noqa: BLE001
pass
def all(self):
with self.lock:
return list(self.records)
def _say(value):
return "?" if value is None else ("%.2f" % value)
# ---- the witness of the whole process ----------------------------------------------------------------------------------------------
class StallWitness:
"""A daemon thread that beats every ``beat_s`` and keeps the gaps over ``stall_s``. A call that holds the GIL (a long call into C) or a
machine with no CPU left for this process delays the beat of every thread alike, so a gap is a stall of the whole worker process, the one
that also holds the gateway's own threads. Times are seconds from ``epoch`` (``time.monotonic()`` of the start of the gateway: the scale
of its records) and ``t``, the wall clock."""
def __init__(self, records, epoch, beat_s=BEAT_S, stall_s=STALL_S, clock=time.monotonic):
self.records, self.epoch, self.beat_s, self.stall_s, self._clock = records, epoch, beat_s, stall_s, clock
self.beats = 0
self.first = self.last = None
self.longest_gap_s = 0.0
self._stop = threading.Event()
self._thread = None
def beat(self):
"""One beat. Never raises: a clock that fails is a record."""
try:
now = self._clock()
if self.last is None:
self.first = now
else:
gap = now - self.last
self.longest_gap_s = max(self.longest_gap_s, gap)
if gap > self.stall_s:
self.records.add({"origin": "witness", "event": "stall", "from_gw": round(self.last - self.epoch, 4),
"to_gw": round(now - self.epoch, 4), "gap_s": round(gap, 4)})
self.last = now
self.beats += 1
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "witness", "event": "a beat could not be made", "error": repr(problem)})
def _run(self):
try:
while not self._stop.wait(self.beat_s):
self.beat()
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "witness", "event": "the witness ended", "error": repr(problem)})
def start(self):
try:
self.beat()
self._thread = threading.Thread(target=self._run, name="far-away-stall-witness", daemon=True)
self._thread.start()
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "witness", "event": "the witness did not start", "error": repr(problem)})
def stop(self):
"""Ends the witness and says what it saw: the last gap (from its last beat to now) is a stall too if it is long."""
try:
self._stop.set()
if self._thread is not None:
self._thread.join(5)
self.beat()
self.records.add({"origin": "witness", "event": "the witness stopped", "beats": self.beats, "beat_s": self.beat_s,
"stall_s": self.stall_s, "longest_gap_s": round(self.longest_gap_s, 4),
"watched_s": None if self.first is None or self.last is None else round(self.last - self.first, 4)})
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "witness", "event": "the witness did not stop cleanly", "error": repr(problem)})
def stalls(self):
return [r for r in self.records.all() if r.get("event") == "stall"]
# ---- the load of the runner -------------------------------------------------------------------------------------------------------
class LoadSampler:
"""The runner's CPU load every ``every_s`` seconds: ``cpu_percent(percpu=False)`` since the previous sample and, where the system has it,
the load average. ``source`` is ``psutil`` (a stand-in in the unit tests)."""
def __init__(self, records, epoch, every_s=LOAD_EVERY_S, source=None, clock=time.monotonic):
self.records, self.epoch, self.every_s, self._clock = records, epoch, every_s, clock
self.source = source
self._stop = threading.Event()
self._thread = None
def sample(self):
"""One sample. Never raises: a source that fails is a record."""
try:
record = {"origin": "load", "event": "sample", "gw": round(self._clock() - self.epoch, 4)}
record["cpu_percent"] = self.source.cpu_percent(percpu=False)
if hasattr(self.source, "getloadavg"):
try:
record["loadavg_1_5_15"] = [round(v, 2) for v in self.source.getloadavg()]
except Exception as problem: # noqa: BLE001
record["loadavg_error"] = repr(problem)
self.records.add(record)
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "load", "event": "a sample could not be taken", "error": repr(problem)})
def _run(self):
try:
while not self._stop.wait(self.every_s):
self.sample()
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "load", "event": "the sampler ended", "error": repr(problem)})
def start(self):
try:
if self.source is None:
import psutil
self.source = psutil
self.source.cpu_percent(percpu=False) # the first reading has no window: it is only the start of the first one
if hasattr(self.source, "getloadavg"):
self.source.getloadavg() # on Windows the first call starts the thread that makes the average
self._thread = threading.Thread(target=self._run, name="far-away-load-sampler", daemon=True)
self._thread.start()
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "load", "event": "the sampler did not start", "error": repr(problem)})
def stop(self):
try:
self._stop.set()
if self._thread is not None:
self._thread.join(5)
self.sample()
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "load", "event": "the sampler did not stop cleanly", "error": repr(problem)})
def samples(self):
return [r for r in self.records.all() if r.get("event") == "sample" and isinstance(r.get("cpu_percent"), (int, float))]
# ---- the core's logger ------------------------------------------------------------------------------------------------------------
class _KeepRecords(logging.Handler):
def __init__(self, records, epoch, clock):
super().__init__(level=logging.DEBUG)
self.records, self.epoch, self._clock = records, epoch, clock
def emit(self, record):
try:
self.records.add({"origin": "core", "event": "log", "logger": record.name, "level": record.levelname,
"message": record.getMessage(), "thread": record.threadName, "gw": round(self._clock() - self.epoch, 4)})
except Exception as problem: # noqa: BLE001 - a message that cannot be formatted is a record, not an error of the core's thread
try:
self.records.add({"origin": "probe", "event": "a log record could not be kept", "logger": getattr(record, "name", None),
"error": repr(problem)})
except Exception: # noqa: BLE001 - not even that: nothing is raised into the logging call of the core
pass
class LogCapture:
"""The records of the logger ``name`` at DEBUG while it is on: its level is set and the handler added at ``start``, and both are put back at
``stop`` whatever happened in between. The logger keeps passing every record on to its parents as before."""
def __init__(self, records, epoch, name=UDP_EXIT_LOGGER, clock=time.monotonic):
self.records, self.name = records, name
self._handler = _KeepRecords(records, epoch, clock)
self._level = None
self._on = False
def start(self):
try:
logger = logging.getLogger(self.name)
self._level = logger.level
logger.addHandler(self._handler)
self._on = True
logger.setLevel(logging.DEBUG)
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "probe", "event": "the log capture did not start", "error": repr(problem)})
def stop(self):
try:
if self._on:
logger = logging.getLogger(self.name)
logger.removeHandler(self._handler)
logger.setLevel(self._level)
self._on = False
except Exception as problem: # noqa: BLE001
self.records.add({"origin": "probe", "event": "the log capture did not stop", "error": repr(problem)})
# ---- the times of the control connections ----------------------------------------------------------------------------------------
def control_times(records):
"""From the records of the watch's control journal (``gateway-control-connections``): for each control connection, in seconds from the start
of the gateway, when it was accepted (connect), when the greeting and the authentication were answered, when the ASSOCIATE was asked and
answered, and the longest time the gateway sat on an answer between the moment it was asked to send it and the moment it was sent.
``None`` is a step that was not seen. Never raises."""
table = {}
try:
for r in records:
conn = r.get("conn")
if conn is None or conn < 0:
continue
row = table.setdefault(conn, {"connect": None, "greeting": None, "authentication": None, "associate_asked": None,
"associate_answered": None, "longest_answer_wait_s": None})
event = r.get("event")
if event == "control connection accepted":
row["connect"] = r.get("gw")
elif event == "request" and r.get("command") == "UDP ASSOCIATE":
row["associate_asked"] = r.get("gw")
elif event == "answer sent":
what = str(r.get("what", ""))
if what.startswith("method selection"):
row["greeting"] = r.get("gw")
elif what.startswith("authentication status"):
row["authentication"] = r.get("gw")
elif r.get("kind") == "associate" and r.get("rep") == 0:
row["associate_answered"] = r.get("gw")
if r.get("gw") is not None and r.get("asked_gw") is not None:
wait = round(r["gw"] - r["asked_gw"], 4)
if row["longest_answer_wait_s"] is None or wait > row["longest_answer_wait_s"]:
row["longest_answer_wait_s"] = wait
except Exception as problem: # noqa: BLE001
table["error"] = repr(problem)
return table
def control_line(table):
"""The control connections in one line: ``#<n> connect|greeting|authentication|ASSOCIATE asked|ASSOCIATE answered`` in seconds from the start of
the gateway, the longest wait inside the gateway for an answer, and a reminder that #0 is the core's (the first accepted)."""
try:
rows = sorted((k, v) for k, v in table.items() if isinstance(k, int))
if not rows:
return "control connections of the gateway: none seen"
shown = " ".join("#%d %s|%s|%s|%s|%s (longest wait in the gateway %ss)" % (
k, _say(v["connect"]), _say(v["greeting"]), _say(v["authentication"]), _say(v["associate_asked"]), _say(v["associate_answered"]),
_say(v["longest_answer_wait_s"])) for k, v in rows[:MESSAGE_CONNECTIONS])
return ("control connections of the gateway, s from its start, connect|greeting answered|authentication answered|ASSOCIATE asked|"
"ASSOCIATE answered (#0 is the first accepted: the core's own measurement), %d of %d: %s" % (min(len(rows), MESSAGE_CONNECTIONS), len(rows), shown))
except Exception as problem: # noqa: BLE001
return "control connections of the gateway: not read (%r)" % (problem,)
def core_line(records):
"""The core's UDP measurement in one line: its DEBUG records and the marks of the test, each with its time in seconds from the start of the gateway."""
try:
parts = []
for r in records:
if r.get("event") == "log":
parts.append("%s: %r at %s" % (r.get("thread"), r.get("message"), _say(r.get("gw"))))
elif r.get("event") == "mark":
parts.append("%s at %s" % (r.get("what"), _say(r.get("gw"))))
return "the core's UDP measurement (logger %s, s from the gateway start): %s" % (UDP_EXIT_LOGGER, "; ".join(parts) or "no record")
except Exception as problem: # noqa: BLE001
return "the core's UDP measurement: not read (%r)" % (problem,)
def process_line(witness, sampler):
"""The stalls of the process and the runner's load in one line each."""
try:
stalls = sorted(witness.stalls(), key=lambda s: -s["gap_s"])
samples = sampler.samples() if sampler is not None else []
if stalls:
said = ", ".join("%.2fs (%.2f to %.2f)" % (s["gap_s"], s["from_gw"], s["to_gw"]) for s in stalls[:MESSAGE_STALLS])
stall = "%d stall(s) of the whole process over %.0f ms, longest first, gap (from to, s from the gateway start): %s" % (
len(stalls), witness.stall_s * 1000, said)
else:
stall = "no stall of the whole process over %.0f ms in %d beats of %.0f ms (longest gap %.3fs)" % (
witness.stall_s * 1000, witness.beats, witness.beat_s * 1000, witness.longest_gap_s)
if samples:
cpu = [s["cpu_percent"] for s in samples]
loads = [s["loadavg_1_5_15"][0] for s in samples if s.get("loadavg_1_5_15")]
load = "runner CPU every %.1fs: %d samples, max %.0f%%, mean %.0f%%, at least 90%% in %d%s" % (
sampler.every_s, len(cpu), max(cpu), sum(cpu) / len(cpu), sum(1 for c in cpu if c >= 90),
"; load average max %.2f" % max(loads) if loads else "")
else:
load = "runner CPU: no sample"
return stall + "\n" + load
except Exception as problem: # noqa: BLE001
return "stall witness and runner load: not read (%r)" % (problem,)
class FarAwayProbes:
"""The three recorders of one gather, started and stopped together. ``epoch`` is ``time.monotonic()`` at the start of the gateway."""
def __init__(self, epoch, load_source=None):
self.epoch = epoch
self.stall_records, self.load_records, self.core_records = Records(), Records(), Records()
self.witness = StallWitness(self.stall_records, epoch)
self.sampler = LoadSampler(self.load_records, epoch, source=load_source)
self.core = LogCapture(self.core_records, epoch)
def start(self):
self.core.start()
self.sampler.start()
self.witness.start()
def stop(self):
self.witness.stop()
self.sampler.stop()
self.core.stop()
def mark(self, what):
"""A moment of the test (the launch that runs the core's measurement starts, returns), on the scale of the core's records."""
self.core_records.add({"origin": "test", "event": "mark", "what": what, "gw": round(time.monotonic() - self.epoch, 4)})
def lines(self, control_records):
"""The failure message: the times of the control connections, the core's measurement, the stalls and the load."""
return "\n".join(["far-away probes:", control_line(control_times(control_records)), core_line(self.core_records.all()),
process_line(self.witness, self.sampler)])
def cells(self, control_records):
return {"control_connection_times_s_from_the_gateway_start": control_times(control_records),
"stalls_of_the_whole_process": self.witness.stalls(), "stall_beats": self.witness.beats,
"longest_gap_between_beats_s": round(self.witness.longest_gap_s, 4),
"runner_load_samples": self.sampler.samples(), "core_udp_exit_log_and_marks": self.core_records.all()}
@@ -0,0 +1,385 @@
"""The recorders a failed far-away gather leaves (tests/_far_away_probes.py, started by ``_Watch`` of tests/test_webrtc_realness.py), no browser.
They say where the time went when the core's UDP measurement or the gather misses its window: the times of the control connections of the
gateway, the DEBUG records of the core's logger of that measurement, a witness of stalls of the whole process, and the runner's load. Each
one is bookkeeping and must never change what it watches, so each is proved twice: it sees what it is made to see (a stall of the whole
process made on purpose, a log record, a slow gateway), and it is made to fail on purpose (a clock, a load source, a message that cannot be
formatted, a record that cannot be kept) and then raises nothing into the test or into a server.
"""
from __future__ import annotations
import ctypes
import logging
import sys
import threading
import time
import pytest
import _far_away_probes as probes
import test_the_far_away_watch_never_breaks_the_gateway as watched
import test_webrtc_realness as realness
from _socks_servers import coherent
pytestmark = pytest.mark.unit
class _Clock:
"""A clock the test moves: each call gives the next value (an exception is raised)."""
def __init__(self, *values):
self.values = list(values)
def __call__(self):
value = self.values.pop(0) if len(self.values) > 1 else self.values[0]
if isinstance(value, Exception):
raise value
return value
def _stalls(records):
return [r for r in records.all() if r["event"] == "stall"]
# ---- the witness of the whole process -------------------------------------------------------------------------------------------------
def test_a_gap_between_two_beats_over_the_threshold_is_a_stall_with_its_times():
records = probes.Records()
witness = probes.StallWitness(records, epoch=100.0, clock=_Clock(100.0, 100.05, 100.10, 101.60, 101.65))
for _ in range(5):
witness.beat()
[stall] = _stalls(records)
assert stall["from_gw"] == pytest.approx(0.1) and stall["to_gw"] == pytest.approx(1.6) and stall["gap_s"] == pytest.approx(1.5)
assert witness.beats == 5 and witness.longest_gap_s == pytest.approx(1.5)
def test_beats_that_keep_their_pace_are_no_stall():
records = probes.Records()
witness = probes.StallWitness(records, epoch=0.0, clock=_Clock(*[i * 0.05 for i in range(40)]))
for _ in range(40):
witness.beat()
assert _stalls(records) == [] and witness.beats == 40
def test_the_end_of_the_watch_counts_the_gap_since_the_last_beat():
"""A process stalled until the test ended has no later beat: stopping makes the last one, and the long gap is said."""
records = probes.Records()
witness = probes.StallWitness(records, epoch=0.0, clock=_Clock(0.0, 0.05, 2.0))
witness.beat()
witness.beat()
witness.stop()
[stall] = _stalls(records)
assert stall["from_gw"] == pytest.approx(0.05) and stall["gap_s"] == pytest.approx(1.95)
assert [r for r in records.all() if r["event"] == "the witness stopped"][0]["beats"] == 3
def _hold_the_gil(seconds):
"""A call into C that keeps the GIL for ``seconds``: every other thread of this process is stopped, as a long call of a library would."""
if sys.platform == "win32":
ctypes.PyDLL("kernel32").Sleep(int(seconds * 1000))
else:
ctypes.PyDLL(None).usleep(int(seconds * 1000000))
def test_a_stall_of_the_whole_process_is_seen_by_the_thread_that_beats():
records = probes.Records()
epoch = time.monotonic()
witness = probes.StallWitness(records, epoch)
witness.start()
try:
time.sleep(0.2)
before = time.monotonic() - epoch
_hold_the_gil(0.6)
after = time.monotonic() - epoch
time.sleep(0.2)
finally:
witness.stop()
stalls = _stalls(records)
assert stalls, records.all()
longest = max(stalls, key=lambda s: s["gap_s"])
assert longest["gap_s"] >= 0.5 and longest["from_gw"] <= before + 0.1 and longest["to_gw"] >= after - 0.1, (longest, before, after)
assert witness.beats > 5 and not witness._thread.is_alive()
def test_a_clock_that_fails_is_a_record_and_the_witness_goes_on():
records = probes.Records()
witness = probes.StallWitness(records, epoch=0.0, clock=_Clock(0.0, RuntimeError("the clock is broken"), 0.1, 0.15))
for _ in range(4):
witness.beat()
said = [r for r in records.all() if r["event"] == "a beat could not be made"]
assert len(said) == 1 and "the clock is broken" in said[0]["error"]
assert witness.beats == 3
def test_records_that_cannot_be_kept_raise_nothing():
records = probes.Records()
records.add({"event": "x", "data": object()})
records.add(None) # not a record at all
records.records = None # a list that is gone
records.add({"event": "y"})
witness = probes.StallWitness(records, epoch=0.0, clock=_Clock(0.0, 5.0))
witness.beat()
witness.beat()
witness.stop()
# ---- the load of the runner -------------------------------------------------------------------------------------------------------------
class _Load:
def __init__(self, cpu=(10.0, 97.5), loadavg=(1.0, 0.5, 0.25)):
self.cpu, self.loadavg = list(cpu), loadavg
self.calls = []
def cpu_percent(self, percpu=None):
self.calls.append(percpu)
value = self.cpu.pop(0) if len(self.cpu) > 1 else self.cpu[0]
if isinstance(value, Exception):
raise value
return value
def getloadavg(self):
if isinstance(self.loadavg, Exception):
raise self.loadavg
return self.loadavg
def test_the_load_is_sampled_with_percpu_false_and_the_load_average():
records, source = probes.Records(), _Load(cpu=(0.0, 12.5))
sampler = probes.LoadSampler(records, epoch=time.monotonic(), source=source)
sampler.start()
sampler.stop()
samples = sampler.samples()
assert samples[-1]["cpu_percent"] == 12.5 and set(source.calls) == {False}
assert samples[-1]["loadavg_1_5_15"] == [1.0, 0.5, 0.25]
def test_a_source_without_a_load_average_gives_the_cpu_only():
class Cpu:
def cpu_percent(self, percpu=None):
return 40.0
records = probes.Records()
sampler = probes.LoadSampler(records, epoch=0.0, source=Cpu())
sampler.sample()
[sample] = sampler.samples()
assert sample["cpu_percent"] == 40.0 and "loadavg_1_5_15" not in sample and "loadavg_error" not in sample
def test_the_real_psutil_gives_a_percentage_and_a_load_average():
records = probes.Records()
sampler = probes.LoadSampler(records, epoch=time.monotonic())
sampler.start()
time.sleep(0.6)
sampler.stop()
samples = sampler.samples()
assert samples and all(0.0 <= s["cpu_percent"] <= 100.0 for s in samples), records.all()
assert all(len(s["loadavg_1_5_15"]) == 3 for s in samples), records.all()
@pytest.mark.parametrize("source", [_Load(cpu=(0.0, RuntimeError("psutil is broken"))), _Load(cpu=(0.0, 1.0), loadavg=OSError("no load"))],
ids=["the_cpu_reading", "the_load_average"])
def test_a_load_source_that_fails_is_a_record_and_raises_nothing(source):
records = probes.Records()
sampler = probes.LoadSampler(records, epoch=0.0, source=source)
sampler.start()
sampler.sample()
sampler.stop()
said = [r for r in records.all() if "error" in r or "loadavg_error" in r]
assert said, records.all()
def test_a_module_that_is_not_there_is_said_and_raises_nothing(monkeypatch):
monkeypatch.setitem(sys.modules, "psutil", None)
records = probes.Records()
sampler = probes.LoadSampler(records, epoch=0.0)
sampler.start()
sampler.stop()
assert [r for r in records.all() if r["event"] == "the sampler did not start"]
# ---- the core's logger ----------------------------------------------------------------------------------------------------------------
def test_the_logger_name_is_the_one_of_the_core():
from invisible_core import _udp_exit
assert probes.UDP_EXIT_LOGGER == _udp_exit.log.name
def test_the_debug_records_of_the_core_are_kept_and_the_logger_is_put_back():
from invisible_core import _udp_exit
logger = logging.getLogger(probes.UDP_EXIT_LOGGER)
level, handlers = logger.level, list(logger.handlers)
logger.setLevel(logging.WARNING) # the level of a run: DEBUG would not reach any handler
try:
records = probes.Records()
capture = probes.LogCapture(records, epoch=time.monotonic())
capture.start()
try:
_udp_exit.log.debug("the UDP exit through the proxy: %s", "unmeasured")
thread = threading.Thread(target=_udp_exit.log.debug, args=("the UDP exit could not be measured: %s", "OSError"),
name="invisible-udp-exit")
thread.start()
thread.join()
finally:
capture.stop()
kept = [(r["message"], r["thread"]) for r in records.all() if r["event"] == "log"]
assert kept == [("the UDP exit through the proxy: unmeasured", threading.current_thread().name),
("the UDP exit could not be measured: OSError", "invisible-udp-exit")]
assert logger.level == logging.WARNING and logger.handlers == handlers
_udp_exit.log.debug("after the capture")
assert len([r for r in records.all() if r["event"] == "log"]) == 2
finally:
logger.setLevel(level)
def test_the_logger_is_put_back_when_the_body_fails():
logger = logging.getLogger(probes.UDP_EXIT_LOGGER)
level, handlers = logger.level, list(logger.handlers)
capture = probes.LogCapture(probes.Records(), epoch=0.0)
with pytest.raises(ZeroDivisionError):
capture.start()
try:
1 / 0
finally:
capture.stop()
assert logger.level == level and logger.handlers == handlers
def test_a_log_record_that_cannot_be_formatted_is_a_record_and_raises_nothing_into_the_core():
logger = logging.getLogger(probes.UDP_EXIT_LOGGER)
records = probes.Records()
capture = probes.LogCapture(records, epoch=0.0)
bad = logging.LogRecord(logger.name, logging.DEBUG, __file__, 1, "%d", ("not a number",), None) # getMessage() raises TypeError
capture.start()
try:
capture._handler.emit(bad) # the handler alone: the other handlers of the run (pytest's) have their own rules
logger.debug("fine")
finally:
capture.stop()
said = [r for r in records.all() if r["event"] == "a log record could not be kept"]
assert said and "TypeError" in said[0]["error"]
assert [r["message"] for r in records.all() if r["event"] == "log"] == ["fine"]
def test_a_clock_that_fails_in_the_handler_raises_nothing_into_the_core():
logger = logging.getLogger(probes.UDP_EXIT_LOGGER)
records = probes.Records()
capture = probes.LogCapture(records, epoch=0.0, clock=_Clock(RuntimeError("the clock is broken")))
capture.start()
try:
logger.debug("a record")
finally:
capture.stop()
assert [r for r in records.all() if r["event"] == "a log record could not be kept"]
# ---- the times of the control connections --------------------------------------------------------------------------------------------
def _control(conn, gw0, wait):
return [
{"event": "control connection accepted", "conn": conn, "gw": gw0},
{"event": "answer sent", "conn": conn, "what": "method selection (0x00 none, 0x02 user/password, 0xff none acceptable)", "gw": gw0 + 0.1,
"asked_gw": gw0 + 0.02, "kind": None},
{"event": "answer sent", "conn": conn, "what": "authentication status (0x00 accepted)", "gw": gw0 + 0.2, "asked_gw": gw0 + 0.12, "kind": None},
{"event": "request", "conn": conn, "command": "UDP ASSOCIATE", "gw": gw0 + 0.25},
{"event": "answer sent", "conn": conn, "what": "reply (REP 0 = succeeded)", "rep": 0, "kind": "associate", "gw": gw0 + 0.26 + wait,
"asked_gw": gw0 + 0.26},
]
def test_the_times_of_a_control_connection_are_read_from_the_watch_and_the_slow_answer_shows():
table = probes.control_times(_control(0, 0.5, 1.5) + _control(1, 2.0, 0.1))
assert table[0]["connect"] == 0.5 and table[0]["greeting"] == 0.6 and table[0]["authentication"] == 0.7
assert table[0]["associate_asked"] == 0.75 and table[0]["associate_answered"] == 2.26 and table[0]["longest_answer_wait_s"] == 1.5
assert table[1]["longest_answer_wait_s"] == 0.1 and table[1]["connect"] == 2.0
line = probes.control_line(table)
assert "#0 0.50|0.60|0.70|0.75|2.26 (longest wait in the gateway 1.50s)" in line and "#1 2.00|2.10|2.20|2.25|2.36" in line
assert "#0 is the first accepted" in line
def test_a_step_that_was_not_seen_is_said_with_a_question_mark_and_a_broken_record_raises_nothing():
line = probes.control_line(probes.control_times([{"event": "control connection accepted", "conn": 0, "gw": 0.25}]))
assert "#0 0.25|?|?|?|?" in line
assert "none seen" in probes.control_line({})
broken = probes.control_line(probes.control_times([object()])) # not a record: nothing is read, and nothing is raised
assert isinstance(broken, str) and ("not read" in broken or "none seen" in broken)
def test_the_message_names_the_core_measurement_the_stalls_and_the_load():
kept = probes.FarAwayProbes(epoch=time.monotonic(), load_source=_Load(cpu=(0.0, 91.0)))
kept.core.start()
try:
kept.mark("launch starts")
logging.getLogger(probes.UDP_EXIT_LOGGER).debug("the UDP exit through the proxy: %s", "unmeasured")
kept.mark("launch returned")
finally:
kept.core.stop()
kept.sampler.start()
kept.sampler.stop()
kept.stall_records.add({"origin": "witness", "event": "stall", "from_gw": 12.3, "to_gw": 13.81, "gap_s": 1.51})
text = kept.lines(_control(0, 0.5, 1.5))
assert "launch starts at" in text and "'the UDP exit through the proxy: unmeasured'" in text and "launch returned at" in text
assert "1 stall(s) of the whole process over 200 ms" in text and "1.51s (12.30 to 13.81)" in text
assert "runner CPU every 0.5s" in text and "max 91%" in text and "load average max 1.00" in text
# ---- the watch on a real gateway ----------------------------------------------------------------------------------------------------
def _watch_with_probes(monkeypatch, load_source):
gateway = coherent(user="alice", password="s3cret")
evidence = watched._Evidence()
evidence.note_cells({})
watch = realness._Watch(gateway, monkeypatch, evidence, "127.0.0.1")
watch.probes.sampler.source = load_source
return gateway, watch, evidence
def test_a_watched_gather_keeps_the_probes_for_the_evidence_and_says_them_in_its_summary(monkeypatch):
gateway, watch, evidence = _watch_with_probes(monkeypatch, _Load(cpu=(0.0, 3.0)))
try:
with watch:
watch.mark("launch starts")
logging.getLogger(probes.UDP_EXIT_LOGGER).debug("the UDP exit through the proxy: %s", "coherent")
answer, _bnd = watched._associate_and_relay(gateway, ("alice", "s3cret"))
watched._the_datagram_was_relayed(gateway, answer)
watch.mark("launch returned")
finally:
gateway.close()
assert {"stall-witness", "runner-load", "core-udp-exit-log", "gateway-control-connections"} <= set(evidence.records)
text = watch.summary()
assert "control connections of the gateway" in text and "#0 " in text and "|" in text
assert "'the UDP exit through the proxy: coherent'" in text and "launch starts at" in text
assert "no stall of the whole process" in text or "stall(s) of the whole process" in text
assert "runner CPU" in text
cells = evidence.cells
assert set(cells) >= {"control_connection_times_s_from_the_gateway_start", "stalls_of_the_whole_process", "runner_load_samples",
"core_udp_exit_log_and_marks", "gateway"}
assert cells["control_connection_times_s_from_the_gateway_start"][0]["associate_answered"] is not None
assert not [h for h in logging.getLogger(probes.UDP_EXIT_LOGGER).handlers if isinstance(h, probes._KeepRecords)]
def test_a_failure_inside_the_watch_carries_the_probes_as_a_note_of_the_exception(monkeypatch):
gateway, watch, _evidence = _watch_with_probes(monkeypatch, _Load(cpu=(0.0, 3.0)))
try:
with pytest.raises(TimeoutError) as raised:
with watch:
raise TimeoutError("no association in 30 s")
finally:
gateway.close()
assert str(raised.value) == "no association in 30 s" # the message is the test's own
assert raised.value.__notes__ and "far-away probes:" in raised.value.__notes__[0]
@pytest.mark.parametrize("breakage", ["clock", "load", "log"])
def test_a_probe_that_breaks_never_stops_the_gateway(monkeypatch, breakage):
gateway, watch, _evidence = _watch_with_probes(monkeypatch, _Load(cpu=(0.0, 3.0)))
if breakage == "clock":
monkeypatch.setattr(watch.probes.witness, "_clock", _Clock(RuntimeError("the clock is broken")))
elif breakage == "load":
watch.probes.sampler.source = _Load(cpu=(0.0, RuntimeError("psutil is broken")))
else:
watch.probes.core.records = None # a list of records that is not there
watch.probes.core._handler.records = None
try:
with watch:
logging.getLogger(probes.UDP_EXIT_LOGGER).debug("a record")
answer, _bnd = watched._associate_and_relay(gateway, ("alice", "s3cret"))
watched._the_datagram_was_relayed(gateway, answer)
assert gateway.associates == 1
assert isinstance(watch.summary(), str)
finally:
gateway.close()
+76 -25
View File
@@ -34,6 +34,7 @@ from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler, HTTPServer
import pytest
from _evidence_on_failure import FailureEvidence
from _far_away_probes import FarAwayProbes
from _host_address import this_host_address
from _socks_servers import MEASURE_NUMBER, STUN_NUMBER, STUN_PORT, Socks5TcpOnly
from _udp_line import bench_report, declared_udp, declared_udp_or_absent, egress_by_proxy, measure_servers
@@ -517,6 +518,11 @@ class _Watch:
evidence.note_records("gateway-control-connections", self.control)
evidence.note_records("gateway-udp-datagrams", self.udp)
evidence.note_records("page-view", self.page)
# The recorders of the machine and of the core's own measurement (tests/_far_away_probes.py): started with the watch, stopped with it.
self.probes = FarAwayProbes(gateway.t0)
evidence.note_records("stall-witness", self.probes.stall_records)
evidence.note_records("runner-load", self.probes.load_records)
evidence.note_records("core-udp-exit-log", self.probes.core_records)
self.bnd_ports = set()
self._reads = threading.local()
self.cells["relay_host"] = relay_host
@@ -524,16 +530,38 @@ class _Watch:
self._wrap_the_sockets(monkeypatch)
def __enter__(self):
if self.active:
self.safely(self.probes.start)
return self
def __exit__(self, exc_type, exc, tb):
if self.active:
self.safely(self.probes.stop)
try:
self.snapshot()
except Exception as problem: # the evidence never hides the failure it is about
sys.stderr.write("gateway evidence: could not be taken: %r\n" % (problem,))
if exc is not None: # a failure that is not an assertion of the test (a wait, a launch) says it too
self.safely(lambda: exc.add_note(self.summary()))
return False
def mark(self, what):
"""A moment of the test on the scale of the core's records (the launch that runs the core's UDP measurement starts, returns)."""
if self.active:
self.safely(lambda: self.probes.mark(what))
def summary(self):
"""The lines a failed gather adds to its message: the control connections' times, the core's UDP measurement, the stalls of the
process and the runner's load (the evidence has them whole). Empty when no evidence is kept. Never raises."""
if not self.active:
return ""
try:
with self.control.lock:
records = list(self.control.records)
return self.probes.lines(records)
except Exception as problem: # noqa: BLE001
return "far-away probes: not read (%r)" % (problem,)
# ---- the clocks ---------------------------------------------------------------------------------------------------------
def _gw(self):
"""Seconds from the start of the gateway (``Gateway.t0``): the scale of its ``requests``, ``accepted``, ``associations`` and ``datagram_log``."""
@@ -821,6 +849,9 @@ class _Watch:
def snapshot(self):
"""The gateway's own lists, taken before it closes (times in seconds from its start; ``wall0`` is that instant on the wall clock)."""
gateway = self.gateway
with self.control.lock:
control = list(self.control.records)
self.safely(lambda: self.cells.update(self.probes.cells(control)))
self.cells["gateway"] = {
"wall0_epoch_seconds_of_the_gateway_start": gateway.wall0,
"udp": gateway.udp, "wants_credentials": gateway.user is not None, "rtt_s": gateway.rtt,
@@ -873,7 +904,9 @@ def _gather_behind_a_coherent_gateway(monkeypatch, credentials, ice_prefs, rtt_m
watch.arm()
launched = _launch_behind(gateway, binary_path=binary, extra_prefs=extra_prefs)
watch.launched(launched)
watch.mark("launch starts")
with launched as browser:
watch.mark("launch returned")
page = browser.new_context().new_page()
page.goto("about:blank")
res = watch.evaluate(page, _RELAY_PROBE_JS, stun)
@@ -888,6 +921,9 @@ def _gather_behind_a_coherent_gateway(monkeypatch, credentials, ice_prefs, rtt_m
f"ICE errors: {res['errors']}; gather timings (ms from the offer): {res['at_ms']}; "
f"datagrams the relay carried: {carried}; STUN requests the server answered: {stun_requests}; "
f"UDP ASSOCIATEs the gateway saw: {associates}; round trip to the gateway: {rtt_ms} ms; {bench}")
probes = watch.summary()
if probes:
verdict += "\n" + probes
return bool(srflx) and (STUN_NUMBER, STUN_PORT) in carried, verdict, res["at_ms"]
@@ -1039,31 +1075,46 @@ def test_a_gather_after_the_page_loaded_through_the_gateway_costs_only_the_road_
from _socks_servers import STUN_NUMBER, STUN_PORT, WEB_ADDRESS, coherent
from _waits import wait_until, watch
stun = f"stun:{STUN_NUMBER}:{STUN_PORT}"
with coherent(user="alice", password="s3cret", relay_host=this_host_address(), rtt_ms=250) as gateway:
monkeypatch.setattr(_geo, "discover_egress_ip", egress_by_proxy(gateway))
extra_prefs = {"media.peerconnection.ice.obfuscate_host_addresses": True}
with _launch_behind(gateway, binary_path=binary, extra_prefs=extra_prefs) as browser:
page = browser.new_context().new_page()
page.goto("http://%s/" % WEB_ADDRESS) # by address: the browser resolves names itself
# the pool makes its associations: wait until the gateway has granted one of the engine's (the first granted is the
# core's probe); the verdict names what it saw if none came
wait_until(lambda: len([a for a in gateway.associations if a[1] is not None]) >= 2, 30,
lambda: page.wait_for_timeout(50))
page.evaluate(_START_A_GATHER_JS, stun)
srflx = watch(lambda: page.evaluate("window.__gather.srflx"), lambda at: at is not None, 30,
lambda: page.wait_for_timeout(50))
gather = page.evaluate("window.__gather")
associations = [list(a) for a in gateway.associations]
via = list(gateway.datagram_via)
born = gather["born"] / 1000.0 - gateway.wall0
seen = (f"candidates: {gather['candidates']}; ICE errors: {gather['errors']}; associations (start, end) seen by the gateway: "
f"{associations}; datagrams and the association each left on: {via}; srflx looks: {srflx.render()}")
assert srflx.ok, "no srflx within 30 s behind a gateway 250 ms away. " + seen
problem = cold_association_problem(associations, via, STUN_NUMBER, born)
assert problem is None, f"{problem}. {seen}"
assert gather["host"] is not None and gather["host"] < gather["srflx"], (
f"the host candidate (at {gather['host']} ms) did not come before the srflx ({gather['srflx']} ms): it waited for the "
f"road to the server. {seen}")
# When it fails it saves, under `invpw-evidence/webrtc-gather-after-load-250/`, what the far-away test saves (cells.json, the control
# connections and datagrams of the gateway with their times, the stall witness, the runner's load and the core's own log of its UDP
# measurement); the lines of the same record are in the message. No assertion, wait or deadline below differs from before.
relay_host = this_host_address()
with FailureEvidence("webrtc-gather-after-load-250") as evidence:
cells = {"test": "gather after the page loaded", "rtt_ms": 250}
evidence.note_cells(cells)
with coherent(user="alice", password="s3cret", relay_host=relay_host, rtt_ms=250) as gateway, \
_Watch(gateway, monkeypatch, evidence, relay_host) as record:
monkeypatch.setattr(_geo, "discover_egress_ip", egress_by_proxy(gateway))
extra_prefs = {"media.peerconnection.ice.obfuscate_host_addresses": True}
launched = _launch_behind(gateway, binary_path=binary, extra_prefs=extra_prefs)
record.mark("launch starts")
with launched as browser:
record.mark("launch returned")
page = browser.new_context().new_page()
page.goto("http://%s/" % WEB_ADDRESS) # by address: the browser resolves names itself
# the pool makes its associations: wait until the gateway has granted one of the engine's (the first granted is the
# core's probe); the verdict names what it saw if none came
wait_until(lambda: len([a for a in gateway.associations if a[1] is not None]) >= 2, 30,
lambda: page.wait_for_timeout(50))
page.evaluate(_START_A_GATHER_JS, stun)
srflx = watch(lambda: page.evaluate("window.__gather.srflx"), lambda at: at is not None, 30,
lambda: page.wait_for_timeout(50))
gather = page.evaluate("window.__gather")
associations = [list(a) for a in gateway.associations]
via = list(gateway.datagram_via)
born = gather["born"] / 1000.0 - gateway.wall0
seen = (f"candidates: {gather['candidates']}; ICE errors: {gather['errors']}; associations (start, end) seen by the gateway: "
f"{associations}; datagrams and the association each left on: {via}; srflx looks: {srflx.render()}")
cells["seen"] = seen
probes = record.summary()
if probes:
seen += "\n" + probes
assert srflx.ok, "no srflx within 30 s behind a gateway 250 ms away. " + seen
problem = cold_association_problem(associations, via, STUN_NUMBER, born)
assert problem is None, f"{problem}. {seen}"
assert gather["host"] is not None and gather["host"] < gather["srflx"], (
f"the host candidate (at {gather['host']} ms) did not come before the srflx ({gather['srflx']} ms): it waited for the "
f"road to the server. {seen}")
@pytest.mark.e2e