ci: a ledger PR checks the version it records; the display-start test without a clock (#540)
* ci: the user-install run of a ledger PR checks the version the PR records, not the one of the tree The ledger pull request of a release is merged after user-install is green, and main may already declare the next version: #534 records 0.56.0 while the tree says 0.57.0, which is not published until that ledger is merged, so the wait on the index for the version of pyproject.toml could never end. A step compares PUBLISHED.json at the base of the pull request with the one at its head (scripts/ci_ledger_added_versions.py): the one added version is INVPW_E2E_VERSION for the wait, the release test (uv add ==X) and the upgrade test (from the release before it to X). No addition, or more than one, is an error that says so. Scheduled and dispatched runs are unchanged. Test: the wait is about the version of the ledger, not of pyproject; base [..0.55.0], head [..0.55.0, 0.56.0], tree 0.57.0 gives 0.56.0. min_tests of the two unit rows +6. * Test: the display start runs off the loop, proved without a clock The test measured the longest reply gap of a second browser against a 100 ms threshold and went red on a loaded GitHub runner (129-134 ms) with no defect in the code. The display stand-in now blocks until the test releases it; while it is blocked the loop must serve the second browser. The cancelled-launch test waits on events instead of sleeping. No test in the file depends on a clock.
This commit is contained in:
1 parent
10821ac225
commit
93d8a40c63
7 files changed
+292
-91
No files matched your search
@@ -101,6 +101,28 @@ jobs:
|
||||
- name: Test harness only
|
||||
run: python -m pip install --upgrade pip pytest packaging uv
|
||||
|
||||
# ⛔ THE VERSION OF A LEDGER PULL REQUEST IS THE ONE IT ADDS TO PUBLISHED.json, NOT THE ONE THE TREE DECLARES.
|
||||
# The ledger PR of a release is merged after this job is green, and the next release's tree can already be on main: ledger #534 recorded
|
||||
# 0.56.0 while the tree said 0.57.0, which is not published until that ledger is merged (its tag asks for it), so a wait on the version of
|
||||
# pyproject.toml could never end and the PR could never merge. The versions are compared as data: the ledger at the base of the pull
|
||||
# request against the ledger at its head. Nothing added is an error (there is no release to check), and so is more than one (the job
|
||||
# installs and launches one version). INVPW_E2E_VERSION then carries it to the wait, the install and the launch below, in every step.
|
||||
# A scheduled or dispatched run has no pull request and no such version: it installs the latest, as before.
|
||||
- name: the version this ledger pull request records
|
||||
if: github.event_name == 'pull_request'
|
||||
shell: bash
|
||||
env:
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git fetch --no-tags --depth=1 origin "$BASE_SHA" "$HEAD_SHA"
|
||||
git show "$BASE_SHA:PUBLISHED.json" > "$RUNNER_TEMP/ledger-base.json"
|
||||
git show "$HEAD_SHA:PUBLISHED.json" > "$RUNNER_TEMP/ledger-head.json"
|
||||
version="$(python scripts/ci_ledger_added_versions.py --base "$RUNNER_TEMP/ledger-base.json" --head "$RUNNER_TEMP/ledger-head.json" --tree-pyproject pyproject.toml)"
|
||||
echo "INVPW_E2E_VERSION=$version" >> "$GITHUB_ENV"
|
||||
echo "::notice::this ledger pull request records invisible-playwright $version"
|
||||
|
||||
# PyPI does not serve a new version to pip the instant twine finishes, and
|
||||
# this workflow runs on the ledger pull request, which the publish run
|
||||
# opens seconds after the upload (it ran on `release:`, just as soon).
|
||||
@@ -132,7 +154,8 @@ jobs:
|
||||
python - <<'PY'
|
||||
import os, subprocess, sys, tempfile, time, tomllib
|
||||
dist = tomllib.load(open("pyproject.toml", "rb"))["project"]["name"]
|
||||
version = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
|
||||
# The version the ledger pull request records (the step above), never the tree's: main may already declare the next one.
|
||||
version = os.environ["INVPW_E2E_VERSION"]
|
||||
deadline = time.monotonic() + 600
|
||||
deadline = min(deadline, time.monotonic() + float(os.environ.get("INDEX_WAIT_SECONDS", "600")))
|
||||
poll = float(os.environ.get("INDEX_WAIT_POLL", "15"))
|
||||
@@ -188,6 +211,8 @@ jobs:
|
||||
# rate-limited walk SKIPS, and a skip is not a check.
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
INVPW_E2E_SOURCE: ${{ github.event.inputs.source || 'index' }}
|
||||
# INVPW_E2E_VERSION (set above on a ledger pull request, absent otherwise) is read by both tests: the release test adds exactly that
|
||||
# version, the upgrade test goes from the one before it to it.
|
||||
shell: bash
|
||||
run: |
|
||||
set -o pipefail # or the tee below would swallow pytest's exit code
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
{"id": "wrapper.e2e.compositing", "giro": "G2", "os": ["linux", "windows"], "min_tests": 9, "exact": true, "tests": ["tests/test_software_compositing_is_declared_e2e.py", "tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The engine DECLARES software compositing on every machine (core: the compositing entries of zoom.stealth.gfx.feature_status carry the VM decision, and on Windows gfx.webrender.software=true, gfx.webrender.software.d3d11=false). 3 = (1) the compositor read from a privileged context is 'WebRender (Software)' on Windows and on Linux (windowUtils.layerManagerType of each window: Troubleshoot.snapshot().graphics throws on this engine, `ext is null`, so it is not the route); (2) the GPU process uses under 1.5 s of CPU on the fixed 10-scene loop of one browser (Windows runner: 0.32 s declared, 2.7-4.2 s not, runs 43652292533 and 43642744101; on Linux it is held to the bound if a GPU process exists); (3) the 86 keys of the page-bytes probe plus the canvas 2D scenes (drawImage scaled with smoothing off/low/medium/high, text with linear/radial/conic gradients) equal tests/data/page_bytes_<os>.json, PNGs on decoded pixels. EXPECTED RED on the core 64.71.0 (tests 1 and 2 on Windows). The reference of Windows holds the 75 stable keys and 6 of the 11 PNG keys of run 43652292533; the five other PNG keys and the new canvas keys, and all of Linux, are written from the first run on the engine of the reference (the failure of test 3 prints RECORD-BEGIN ... RECORD-END with the entries to merge): a reference that is not complete is red, never skipped. 9 = those 3 + the 6 families of tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py (from firefox-66, engine_at_least): a screenshot draws the text of Arial, Times New Roman, Consolas and Segoe UI, with accents, the typographic apostrophe, the euro sign, Chinese, Arabic and Russian, and of MS PGothic (face 2 of msgothic5_32.ttc: Japanese and Latin) and NSimSun (face 1 of simsun.ttc: Chinese), two faces that are not the first of their collection, with the same bytes as the content process drew them in a canvas (an SVG image with a foreignObject of the same markup), cut from the same page.screenshot, on both systems and with no threshold. EXPECTED RED on every engine that rebuilds the text in the parent with another font than the bundle (Linux: fontconfig answers DejaVu Sans), and skipped, hence red here, on an engine older than firefox-66. It saves the screenshot, the two boxes and a result.json under RUNNER_TEMP/invpw-evidence."},
|
||||
{"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": 2144, "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_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_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_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_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_css_calc_is_windows_e2e.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_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_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.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.py", "tests/test_prefs_composition_arm.py", "tests/test_preload_newtab_is_written_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_broLine truncated
|
||||
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2145, "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_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_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_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_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_css_calc_is_windows_e2e.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_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_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.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.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_composition_arm_on_windows.py", "tests/test_preload_newtab_is_written_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proLine truncated
|
||||
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2150, "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_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_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_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_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_css_calc_is_windows_e2e.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_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_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.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.py", "tests/test_prefs_composition_arm.py", "tests/test_preload_newtab_is_written_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_broLine truncated
|
||||
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2151, "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_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_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_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_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_css_calc_is_windows_e2e.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_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_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.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.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_composition_arm_on_windows.py", "tests/test_preload_newtab_is_written_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proLine truncated
|
||||
]
|
||||
@@ -0,0 +1,70 @@
|
||||
"""The version a ledger pull request is about: the one it ADDS to PUBLISHED.json, not the one the tree declares.
|
||||
|
||||
python scripts/ci_ledger_added_versions.py --base <ledger-at-base.json> --head <ledger-at-head.json> [--tree-pyproject pyproject.toml]
|
||||
|
||||
The ledger PR of a release is opened after the upload and merged after `user-install` is green, so by the time it runs main may already declare the
|
||||
NEXT version (the tree says 0.57.0 while the PR records 0.56.0, and 0.57.0 is not published until this PR is merged). Asking the index for the
|
||||
version of pyproject.toml waited for something that does not exist yet. The ledger is the record of what was published: the version of the PR is
|
||||
the entry its head has and its base does not.
|
||||
|
||||
Prints the one added version on stdout. Exits 1, with a line on stderr, when the PR adds none (a ledger PR that records nothing has nothing to
|
||||
install) or more than one (the job installs and launches one version; two entries in one PR is a ledger that skipped a merge, not a run to
|
||||
guess at). With ``--tree-pyproject`` the version of the tree is only reported on stderr, never used.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Refused(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def versions_of(ledger_text: str, where: str) -> list[str]:
|
||||
try:
|
||||
data = json.loads(ledger_text)
|
||||
return [str(entry["version"]) for entry in data["released"]]
|
||||
except (ValueError, KeyError, TypeError) as exc:
|
||||
raise Refused("the ledger %s cannot be read: %s: %s" % (where, type(exc).__name__, exc))
|
||||
|
||||
|
||||
def added_versions(base_text: str, head_text: str) -> list[str]:
|
||||
"""The versions the head ledger has and the base ledger does not, in the order of the head."""
|
||||
have = set(versions_of(base_text, "of the base"))
|
||||
return [v for v in versions_of(head_text, "of the head") if v not in have]
|
||||
|
||||
|
||||
def the_version_of_the_pr(base_text: str, head_text: str) -> str:
|
||||
added = added_versions(base_text, head_text)
|
||||
if not added:
|
||||
raise Refused("this pull request adds no version to PUBLISHED.json: there is no release to install and launch")
|
||||
if len(added) > 1:
|
||||
raise Refused("this pull request adds %d versions to PUBLISHED.json (%s): the job checks one release per ledger pull request"
|
||||
% (len(added), ", ".join(added)))
|
||||
return added[0]
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
ap.add_argument("--base", required=True, help="PUBLISHED.json as the base of the pull request has it")
|
||||
ap.add_argument("--head", required=True, help="PUBLISHED.json as the head of the pull request has it")
|
||||
ap.add_argument("--tree-pyproject", help="reported only: the tree's version is not the one of the pull request")
|
||||
args = ap.parse_args(argv)
|
||||
try:
|
||||
version = the_version_of_the_pr(Path(args.base).read_text(encoding="utf-8"), Path(args.head).read_text(encoding="utf-8"))
|
||||
except (Refused, OSError) as exc:
|
||||
print("::error::%s" % exc, file=sys.stderr)
|
||||
return 1
|
||||
if args.tree_pyproject:
|
||||
import tomllib
|
||||
tree = tomllib.loads(Path(args.tree_pyproject).read_text(encoding="utf-8"))["project"]["version"]
|
||||
print("::notice::the pull request records %s; the tree declares %s (not used)" % (version, tree), file=sys.stderr)
|
||||
print(version)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -269,6 +269,12 @@ def clean_venv(workspace: Path, isolated_cache_env: dict) -> Path:
|
||||
add = [i for i, line in enumerate(lines) if line.split()[:3] == ["uv", "add", DIST]]
|
||||
assert len(add) == 1, lines
|
||||
lines[add[0]] = f'uv add "{DIST} @ git+{REPO_URL}@{REV}"'
|
||||
elif os.environ.get("INVPW_E2E_VERSION"):
|
||||
# A ledger pull request names the version it records (`user-install.yml`): that one is installed, not "the latest" of the index, which
|
||||
# can be a different one (the tree on main may declare, and the index may by then serve, the next release).
|
||||
add = [i for i, line in enumerate(lines) if line.split()[:3] == ["uv", "add", DIST]]
|
||||
assert len(add) == 1, lines
|
||||
lines[add[0]] = f'uv add "{DIST}=={os.environ["INVPW_E2E_VERSION"]}"'
|
||||
home = workspace / "home"
|
||||
home.mkdir(exist_ok=True)
|
||||
run_readme_block(lines, cwd=workspace, home=home, env=isolated_cache_env)
|
||||
|
||||
@@ -71,10 +71,11 @@ def _tool(tmp_path, name, plan):
|
||||
def _run_the_wait(tmp_path, pip="y", uv="y", *, seconds=3.0, poll=0.05, call_seconds=None):
|
||||
"""Run the script of the step in a project named ``invisible-playwright`` 9.9.9, with a ``pip`` and a ``uv`` that answer as their plans say.
|
||||
Returns (completed process, pip calls, uv calls)."""
|
||||
(tmp_path / "pyproject.toml").write_text('[project]\nname = "invisible-playwright"\nversion = "9.9.9"\n', encoding="utf-8")
|
||||
# The tree declares 0.99.0 and the ledger pull request records 9.9.9 (what the step before the wait computes): the wait is about the latter.
|
||||
(tmp_path / "pyproject.toml").write_text('[project]\nname = "invisible-playwright"\nversion = "0.99.0"\n', encoding="utf-8")
|
||||
_tool(tmp_path, "pip", pip)
|
||||
_tool(tmp_path, "uv", uv)
|
||||
env = dict(os.environ, PYTHONPATH=str(tmp_path / "shim"), INDEX_WAIT_SECONDS=str(seconds), INDEX_WAIT_POLL=str(poll))
|
||||
env = dict(os.environ, PYTHONPATH=str(tmp_path / "shim"), INDEX_WAIT_SECONDS=str(seconds), INDEX_WAIT_POLL=str(poll), INVPW_E2E_VERSION="9.9.9")
|
||||
if call_seconds is not None:
|
||||
env["INDEX_WAIT_CALL_SECONDS"] = str(call_seconds)
|
||||
try:
|
||||
@@ -178,3 +179,71 @@ def test_the_wait_step_still_passes_the_gate_of_the_core():
|
||||
def test_the_upgrade_goes_from_the_second_newest_to_the_newest_of_one_listing():
|
||||
import test_upgrade_e2e as upgrade
|
||||
assert upgrade._previous_and_latest(["0.48.0", "0.49.1", "0.50.1"]) == ("0.49.1", "0.50.1")
|
||||
|
||||
|
||||
# ---- the version of a ledger pull request is the one it adds to PUBLISHED.json, not the tree's ------------------------------------------------
|
||||
# Ledger #534 recorded 0.56.0 while main already declared 0.57.0 (not published until that ledger is merged): the wait asked the index for the
|
||||
# version of pyproject.toml, which does not exist, and the pull request could never turn green.
|
||||
|
||||
def _ledger(*versions):
|
||||
import json
|
||||
return json.dumps({"comment": "x", "schema": 1, "released": [{"version": v} for v in versions]})
|
||||
|
||||
|
||||
def _added_versions_script():
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location("ci_ledger_added_versions_under_test", ROOT / "scripts" / "ci_ledger_added_versions.py")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_the_version_of_the_pull_request_is_the_one_it_adds_not_the_one_of_the_tree(tmp_path):
|
||||
"""The case of #534: base [..0.55.0], head [..0.55.0, 0.56.0], tree 0.57.0 -> 0.56.0 (through the command the step runs)."""
|
||||
(tmp_path / "base.json").write_text(_ledger("0.54.0", "0.55.0"), encoding="utf-8")
|
||||
(tmp_path / "head.json").write_text(_ledger("0.54.0", "0.55.0", "0.56.0"), encoding="utf-8")
|
||||
(tmp_path / "pyproject.toml").write_text('[project]\nname = "invisible-playwright"\nversion = "0.57.0"\n', encoding="utf-8")
|
||||
r = subprocess.run([sys.executable, str(ROOT / "scripts" / "ci_ledger_added_versions.py"), "--base", "base.json", "--head", "head.json",
|
||||
"--tree-pyproject", "pyproject.toml"], cwd=tmp_path, capture_output=True, text=True, timeout=60)
|
||||
assert r.returncode == 0, r.stdout + r.stderr
|
||||
assert r.stdout.strip() == "0.56.0", r.stdout + r.stderr
|
||||
assert "the tree declares 0.57.0 (not used)" in r.stderr
|
||||
|
||||
|
||||
def test_a_ledger_pull_request_that_adds_nothing_is_an_error_that_says_so():
|
||||
module = _added_versions_script()
|
||||
with pytest.raises(module.Refused, match="adds no version to PUBLISHED.json"):
|
||||
module.the_version_of_the_pr(_ledger("0.54.0", "0.55.0"), _ledger("0.54.0", "0.55.0"))
|
||||
|
||||
|
||||
def test_a_ledger_pull_request_that_adds_two_versions_is_an_error_naming_both():
|
||||
module = _added_versions_script()
|
||||
with pytest.raises(module.Refused, match=r"adds 2 versions .*0\.56\.0, 0\.57\.0"):
|
||||
module.the_version_of_the_pr(_ledger("0.55.0"), _ledger("0.55.0", "0.56.0", "0.57.0"))
|
||||
|
||||
|
||||
def test_a_version_the_head_dropped_is_not_an_addition():
|
||||
module = _added_versions_script()
|
||||
assert module.added_versions(_ledger("0.54.0", "0.55.0"), _ledger("0.55.0", "0.56.0")) == ["0.56.0"]
|
||||
|
||||
|
||||
def test_the_install_job_takes_the_version_of_a_pull_request_from_the_ledger_and_not_from_the_tree():
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
assert '["project"]["version"]' not in text, "a step reads the version of the tree: a ledger pull request is not about it"
|
||||
step = text.index("- name: the version this ledger pull request records")
|
||||
wait = text.index("- name: wait for the index to serve this version")
|
||||
assert step < wait, "the version is computed after the wait that needs it"
|
||||
block = text[step:wait]
|
||||
assert "if: github.event_name == 'pull_request'" in block
|
||||
assert "github.event.pull_request.base.sha" in block and "scripts/ci_ledger_added_versions.py" in block
|
||||
assert 'INVPW_E2E_VERSION=$version" >> "$GITHUB_ENV"' in block
|
||||
assert 'os.environ["INVPW_E2E_VERSION"]' in text[wait:]
|
||||
|
||||
|
||||
def test_the_upgrade_goes_to_the_version_the_pull_request_records_from_the_one_before_it():
|
||||
import test_upgrade_e2e as upgrade
|
||||
listing = ["0.54.0", "0.55.0", "0.56.0", "0.57.0"]
|
||||
assert upgrade._previous_and_latest(listing, "0.56.0") == ("0.55.0", "0.56.0")
|
||||
assert upgrade._previous_and_latest(listing) == ("0.56.0", "0.57.0")
|
||||
with pytest.raises(AssertionError, match="lists no 0.58.0"):
|
||||
upgrade._previous_and_latest(listing, "0.58.0")
|
||||
@@ -195,11 +195,20 @@ def _pinned_core(py: Path) -> str:
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def _previous_and_latest(released: list[str]) -> tuple[str, str]:
|
||||
def _previous_and_latest(released: list[str], target: str | None = None) -> tuple[str, str]:
|
||||
"""The release to upgrade FROM and the one to upgrade TO, both from the one listing the install then uses: the two
|
||||
newest of ``released`` (newest last). A bare ``--upgrade`` asks the index again for "the latest", and an index page
|
||||
that lags (run of the ledger of 0.50.1: the listing had 0.50.1, the upgrade resolved 0.49.1) answers with the old one."""
|
||||
return released[-2], released[-1]
|
||||
that lags (run of the ledger of 0.50.1: the listing had 0.50.1, the upgrade resolved 0.49.1) answers with the old one.
|
||||
|
||||
``target`` is the version a ledger pull request records (``INVPW_E2E_VERSION``, `user-install.yml`): the upgrade goes TO it and FROM the release
|
||||
before it in the listing, whatever newer ones the index has by then. A target the listing does not have is an error, not a fallback."""
|
||||
if target is None:
|
||||
return released[-2], released[-1]
|
||||
assert target in released, "the index lists no %s (it lists %s)" % (target, ", ".join(released[-5:]))
|
||||
at = released.index(target)
|
||||
if at == 0:
|
||||
pytest.skip("%s is the first release of the index; nothing to upgrade FROM" % target)
|
||||
return released[at - 1], target
|
||||
|
||||
|
||||
def _released_versions(py: Path, dist: str) -> list[str]:
|
||||
@@ -237,7 +246,7 @@ def test_upgrading_from_the_previous_release_moves_the_core_too(workspace: Path)
|
||||
released = _released_versions(py, WRAPPER)
|
||||
if len(released) < 2:
|
||||
pytest.skip("only one release on the index; nothing to upgrade FROM")
|
||||
previous, latest = _previous_and_latest(released)
|
||||
previous, latest = _previous_and_latest(released, os.environ.get("INVPW_E2E_VERSION") or None)
|
||||
|
||||
_run([str(py), "-m", "pip", "install", "--no-cache-dir",
|
||||
f"{WRAPPER}=={previous}"], timeout=900)
|
||||
|
||||
@@ -14,7 +14,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import threading
|
||||
import time
|
||||
import types
|
||||
|
||||
import pytest
|
||||
@@ -23,23 +22,37 @@ from invisible_core.launch import FontManifestMismatch
|
||||
|
||||
from invisible_playwright import _session, async_api
|
||||
|
||||
START_SECONDS = 0.5
|
||||
#: Safety net only, never a measure: how long a worker may wait for the test to
|
||||
#: release it, and how long the test may wait for a worker, before a hang is
|
||||
#: turned into a failure. A healthy run never comes near it.
|
||||
SAFETY_SECONDS = 30
|
||||
|
||||
|
||||
class SlowDisplay:
|
||||
"""Stand-in for a display whose start takes 500 ms."""
|
||||
"""Stand-in for a display whose start does not return until the test says so.
|
||||
|
||||
No clock decides anything: `start` announces that it is running (`entered`)
|
||||
and then waits for `release`. While it waits, the test checks that the loop
|
||||
still serves; only then it sets `release`.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.started_on = None
|
||||
self.stopped = 0
|
||||
self.release = None
|
||||
self.entered = threading.Event()
|
||||
self.release = threading.Event()
|
||||
self.returned = threading.Event()
|
||||
self.stop_called = threading.Event()
|
||||
|
||||
def start(self) -> None:
|
||||
self.started_on = threading.get_ident()
|
||||
time.sleep(START_SECONDS)
|
||||
self.entered.set()
|
||||
self.release.wait(SAFETY_SECONDS)
|
||||
self.returned.set()
|
||||
|
||||
def stop(self) -> None:
|
||||
self.stopped += 1
|
||||
self.stop_called.set()
|
||||
|
||||
def launch_env(self):
|
||||
return {}
|
||||
@@ -59,11 +72,10 @@ def slow(monkeypatch):
|
||||
monkeypatch.delenv(_session.TRUE_HEADLESS_ENV, raising=False)
|
||||
monkeypatch.setattr(_session, "make_virtual_display", lambda: vd)
|
||||
monkeypatch.setattr(_session, "build_env", refuse)
|
||||
# Composing the prefs is its own ~100 ms of CPU on a cold process and is not
|
||||
# the subject: the test measures the display start alone.
|
||||
# Composing the prefs is not the subject: the test is about the display start alone.
|
||||
monkeypatch.setattr(async_api.InvisiblePlaywright, "_build_prefs", lambda _s: {})
|
||||
# Nor is the teardown's process scan (~100 ms on a host with many
|
||||
# processes): a stand-in that does only what this test checks, stop the display.
|
||||
# Nor is the teardown's process scan: a stand-in that does only what this
|
||||
# test checks, stop the display.
|
||||
async def teardown(self):
|
||||
vd, self._virtual_display = self._virtual_display, None
|
||||
if vd is not None:
|
||||
@@ -76,33 +88,37 @@ def slow(monkeypatch):
|
||||
|
||||
|
||||
def test_a_second_browser_is_served_while_the_first_starts_its_display(slow):
|
||||
gaps = []
|
||||
"""While the first browser's display start is in progress (blocked until the
|
||||
test lets it return), the loop answers a second browser. If the start ran on
|
||||
the loop, the loop would stand still inside it and the second browser could
|
||||
answer only after the start had returned."""
|
||||
served = {}
|
||||
|
||||
async def second_browser():
|
||||
# Another browser on this loop asks for a reply every 10 ms while the
|
||||
# first one launches. A reply later than 100 ms means the loop was held.
|
||||
last = time.perf_counter()
|
||||
while True:
|
||||
await asyncio.sleep(0.01)
|
||||
now = time.perf_counter()
|
||||
gaps.append(now - last)
|
||||
last = now
|
||||
# Another browser on this loop: a few round trips through the loop, each
|
||||
# one a turn of the loop that the first browser must not be holding.
|
||||
for _ in range(5):
|
||||
await asyncio.sleep(0)
|
||||
served["while_start_in_progress"] = not slow.returned.is_set()
|
||||
|
||||
async def run():
|
||||
first = async_api.InvisiblePlaywright(seed=7, headless=True)
|
||||
other = asyncio.ensure_future(second_browser())
|
||||
await asyncio.sleep(0.05)
|
||||
launch = asyncio.ensure_future(first.__aenter__())
|
||||
# The display start is running (in its worker) and waiting for the test.
|
||||
assert await asyncio.to_thread(slow.entered.wait, SAFETY_SECONDS), "the display start never began"
|
||||
await second_browser()
|
||||
slow.release.set()
|
||||
with pytest.raises(FontManifestMismatch):
|
||||
await launch
|
||||
await asyncio.sleep(0.05) # let the ticker record the last gap
|
||||
other.cancel()
|
||||
await asyncio.wait_for(launch, SAFETY_SECONDS)
|
||||
return first
|
||||
|
||||
first = asyncio.run(run())
|
||||
assert len(gaps) > 5 and max(gaps) < 0.1, (
|
||||
"the second browser waited %.0f ms for a reply: the display start ran "
|
||||
"on the loop" % (max(gaps) * 1000))
|
||||
try:
|
||||
first = asyncio.run(run())
|
||||
finally:
|
||||
slow.release.set()
|
||||
assert served.get("while_start_in_progress"), (
|
||||
"the second browser was served only after the display start had returned: "
|
||||
"the start ran on the loop")
|
||||
assert slow.started_on is not None
|
||||
assert slow.started_on != threading.get_ident(), "the start ran on the loop thread"
|
||||
# The surface is still created, and still stopped by a failed launch.
|
||||
@@ -114,64 +130,70 @@ def test_a_launch_cancelled_during_the_display_start_leaves_no_display(slow):
|
||||
async def run():
|
||||
first = async_api.InvisiblePlaywright(seed=7, headless=True)
|
||||
launch = asyncio.ensure_future(first.__aenter__())
|
||||
await asyncio.sleep(0.1) # the start is in its worker
|
||||
# The start is in its worker, waiting for the test.
|
||||
assert await asyncio.to_thread(slow.entered.wait, SAFETY_SECONDS), "the display start never began"
|
||||
launch.cancel()
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await launch
|
||||
await asyncio.sleep(START_SECONDS + 0.3) # the worker finishes
|
||||
slow.release.set() # the worker finishes
|
||||
# The surface it created for nobody is released on the worker's end.
|
||||
assert await asyncio.to_thread(slow.stop_called.wait, SAFETY_SECONDS), "a display started for a cancelled launch was left running"
|
||||
return first
|
||||
|
||||
asyncio.run(run())
|
||||
try:
|
||||
asyncio.run(run())
|
||||
finally:
|
||||
slow.release.set()
|
||||
assert slow.stopped == 1, "a display started for a cancelled launch was left running"
|
||||
|
||||
|
||||
# -- one decision for both APIs ----------------------------------------------
|
||||
|
||||
class QuickDisplay:
|
||||
def __init__(self) -> None:
|
||||
self.started = 0
|
||||
|
||||
def start(self) -> None:
|
||||
self.started += 1
|
||||
|
||||
def stop(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize("headless", [False, True])
|
||||
@pytest.mark.parametrize("true_headless", [False, True])
|
||||
@pytest.mark.parametrize("platform_has_display", [True, False])
|
||||
def test_sync_and_async_make_the_same_decision(monkeypatch, headless, true_headless,
|
||||
platform_has_display):
|
||||
"""The same inputs give the same answer, the same display and the same
|
||||
started/recorded facts on both paths: the decision lives in one function."""
|
||||
from invisible_playwright import launcher
|
||||
|
||||
if true_headless:
|
||||
monkeypatch.setenv(_session.TRUE_HEADLESS_ENV, "1")
|
||||
else:
|
||||
monkeypatch.delenv(_session.TRUE_HEADLESS_ENV, raising=False)
|
||||
monkeypatch.setattr(
|
||||
_session, "make_virtual_display",
|
||||
lambda: QuickDisplay() if platform_has_display else None)
|
||||
|
||||
def outcome(session, result):
|
||||
vd = session._virtual_display
|
||||
return (result, vd is not None, vd.started if vd is not None else None)
|
||||
|
||||
sync = launcher.InvisiblePlaywright(seed=7, headless=headless)
|
||||
got_sync = outcome(sync, sync._resolve_headless())
|
||||
|
||||
use = async_api.InvisiblePlaywright(seed=7, headless=headless)
|
||||
got_async = outcome(use, asyncio.run(use._resolve_headless_async()))
|
||||
|
||||
assert got_sync == got_async
|
||||
# And the decision itself, for the record.
|
||||
if not headless:
|
||||
assert got_sync == (False, False, None)
|
||||
elif true_headless:
|
||||
assert got_sync == (True, False, None)
|
||||
elif platform_has_display:
|
||||
assert got_sync == (False, True, 1)
|
||||
else:
|
||||
assert got_sync == (False, False, None)
|
||||
|
||||
|
||||
# -- one decision for both APIs ----------------------------------------------
|
||||
|
||||
class QuickDisplay:
|
||||
def __init__(self) -> None:
|
||||
self.started = 0
|
||||
|
||||
def start(self) -> None:
|
||||
self.started += 1
|
||||
|
||||
def stop(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize("headless", [False, True])
|
||||
@pytest.mark.parametrize("true_headless", [False, True])
|
||||
@pytest.mark.parametrize("platform_has_display", [True, False])
|
||||
def test_sync_and_async_make_the_same_decision(monkeypatch, headless, true_headless,
|
||||
platform_has_display):
|
||||
"""The same inputs give the same answer, the same display and the same
|
||||
started/recorded facts on both paths: the decision lives in one function."""
|
||||
from invisible_playwright import launcher
|
||||
|
||||
if true_headless:
|
||||
monkeypatch.setenv(_session.TRUE_HEADLESS_ENV, "1")
|
||||
else:
|
||||
monkeypatch.delenv(_session.TRUE_HEADLESS_ENV, raising=False)
|
||||
monkeypatch.setattr(
|
||||
_session, "make_virtual_display",
|
||||
lambda: QuickDisplay() if platform_has_display else None)
|
||||
|
||||
def outcome(session, result):
|
||||
vd = session._virtual_display
|
||||
return (result, vd is not None, vd.started if vd is not None else None)
|
||||
|
||||
sync = launcher.InvisiblePlaywright(seed=7, headless=headless)
|
||||
got_sync = outcome(sync, sync._resolve_headless())
|
||||
|
||||
use = async_api.InvisiblePlaywright(seed=7, headless=headless)
|
||||
got_async = outcome(use, asyncio.run(use._resolve_headless_async()))
|
||||
|
||||
assert got_sync == got_async
|
||||
# And the decision itself, for the record.
|
||||
if not headless:
|
||||
assert got_sync == (False, False, None)
|
||||
elif true_headless:
|
||||
assert got_sync == (True, False, None)
|
||||
elif platform_has_display:
|
||||
assert got_sync == (False, True, 1)
|
||||
else:
|
||||
assert got_sync == (False, False, None)
|
||||
Reference in new issue
Block a user