tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit afe117bf0e8143fccb96a0165e1a9f2ca72b6a49
parent e55de54f2e2bbfc8e54884023fcf65af6406a291
Author: Rob Wu <rob@robwu.nl>
Date:   Fri, 17 Oct 2025 08:46:13 +0000

Bug 1729546 - Move test_subprocess_round_trip_perf to its own file and unskip some r=florian

... and add references to another file that copied the test structure,
plus pointers to bug comments highlighting the fragility of these tests
on busy systems.

Differential Revision: https://phabricator.services.mozilla.com/D267891

Diffstat:
Mtoolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js | 8++++++++
Mtoolkit/modules/subprocess/test/xpcshell/test_subprocess.js | 54------------------------------------------------------
Atoolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtoolkit/modules/subprocess/test/xpcshell/xpcshell.toml | 6++----
4 files changed, 85 insertions(+), 58 deletions(-)

diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js b/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js @@ -2,6 +2,14 @@ /* vim: set sts=2 sw=2 et tw=80: */ "use strict"; +// This test verifies that NativeMessaging is reasonably fast. +// Subprocess is the backend to NativeMessaging and has a similar test at: +// toolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js +// +// NOTE: This test has fundamental issues that may cause timeouts or longer runs +// on slow, resource-constrained devices. See +// https://bugzilla.mozilla.org/show_bug.cgi?id=1951522#c31 + let max_round_trip_time_ms = 90; const MAX_ROUND_TRIP_TIME_MS = max_round_trip_time_ms; diff --git a/toolkit/modules/subprocess/test/xpcshell/test_subprocess.js b/toolkit/modules/subprocess/test/xpcshell/test_subprocess.js @@ -5,12 +5,6 @@ const { setTimeout } = ChromeUtils.importESModule( "resource://gre/modules/Timer.sys.mjs" ); -let max_round_trip_time_ms = 90; - -const MAX_ROUND_TRIP_TIME_MS = max_round_trip_time_ms; - -const MAX_RETRIES = 5; - let PYTHON; let PYTHON_BIN; let PYTHON_DIR; @@ -176,54 +170,6 @@ add_task(async function test_subprocess_huge() { equal(exitCode, 0, "Got expected exit code"); }); -add_task( - { skip_if: () => mozinfo.ccov }, - async function test_subprocess_round_trip_perf() { - let roundTripTime = Infinity; - for ( - let i = 0; - i < MAX_RETRIES && roundTripTime > MAX_ROUND_TRIP_TIME_MS; - i++ - ) { - let proc = await Subprocess.call({ - command: PYTHON, - arguments: ["-u", TEST_SCRIPT, "echo"], - }); - - const LINE = "I'm a leaf on the wind.\n"; - - let now = Date.now(); - const COUNT = 1000; - for (let j = 0; j < COUNT; j++) { - let [output] = await Promise.all([ - read(proc.stdout), - proc.stdin.write(LINE), - ]); - - // We don't want to log this for every iteration, but we still need - // to fail if it goes wrong. - if (output !== LINE) { - equal(output, LINE, "Got expected output"); - } - } - - roundTripTime = (Date.now() - now) / COUNT; - - await proc.stdin.close(); - - let { exitCode } = await proc.wait(); - - equal(exitCode, 0, "Got expected exit code"); - } - - Assert.lessOrEqual( - roundTripTime, - MAX_ROUND_TRIP_TIME_MS, - `Expected round trip time (${roundTripTime}ms) to be less than ${MAX_ROUND_TRIP_TIME_MS}ms` - ); - } -); - add_task(async function test_subprocess_stderr_default() { const LINE1 = "I'm a leaf on the wind.\n"; const LINE2 = "Watch how I soar.\n"; diff --git a/toolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js b/toolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js @@ -0,0 +1,75 @@ +"use strict"; + +// This test verifies that Subprocess is reasonably fast. +// NativeMessaging is a consumer of Subprocess and has a similar test at: +// toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js +// +// NOTE: This test has fundamental issues that may cause timeouts or longer runs +// on slow, resource-constrained devices. See +// https://bugzilla.mozilla.org/show_bug.cgi?id=1729546#c4 and +// https://bugzilla.mozilla.org/show_bug.cgi?id=1951522#c31 + +let max_round_trip_time_ms = 90; + +const MAX_ROUND_TRIP_TIME_MS = max_round_trip_time_ms; + +const MAX_RETRIES = 5; + +let PYTHON; + +const TEST_SCRIPT = do_get_file("data_test_script.py").path; + +let read = pipe => { + return pipe.readUint32().then(count => { + return pipe.readString(count); + }); +}; + +add_setup(async function setup() { + PYTHON = await Subprocess.pathSearch(Services.env.get("PYTHON")); +}); + +add_task(async function test_subprocess_round_trip_perf() { + let roundTripTime = Infinity; + for ( + let i = 0; + i < MAX_RETRIES && roundTripTime > MAX_ROUND_TRIP_TIME_MS; + i++ + ) { + let proc = await Subprocess.call({ + command: PYTHON, + arguments: ["-u", TEST_SCRIPT, "echo"], + }); + + const LINE = "I'm a leaf on the wind.\n"; + + let now = Date.now(); + const COUNT = 1000; + for (let j = 0; j < COUNT; j++) { + let [output] = await Promise.all([ + read(proc.stdout), + proc.stdin.write(LINE), + ]); + + // We don't want to log this for every iteration, but we still need + // to fail if it goes wrong. + if (output !== LINE) { + equal(output, LINE, "Got expected output"); + } + } + + roundTripTime = (Date.now() - now) / COUNT; + + await proc.stdin.close(); + + let { exitCode } = await proc.wait(); + + equal(exitCode, 0, "Got expected exit code"); + } + + Assert.lessOrEqual( + roundTripTime, + MAX_ROUND_TRIP_TIME_MS, + `Expected round trip time (${roundTripTime}ms) to be less than ${MAX_ROUND_TRIP_TIME_MS}ms` + ); +}); diff --git a/toolkit/modules/subprocess/test/xpcshell/xpcshell.toml b/toolkit/modules/subprocess/test/xpcshell/xpcshell.toml @@ -10,10 +10,6 @@ support-files = [ ] ["test_subprocess.js"] -skip-if = [ - "verify", - "os == 'mac' && os_version == '11.20' && arch == 'aarch64'", # bug 1729546 -] ["test_subprocess_child.js"] @@ -27,4 +23,6 @@ skip-if = [ ["test_subprocess_pathSearch.js"] +["test_subprocess_perf.js"] + ["test_subprocess_polling.js"]