diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/terminator/tests | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/terminator/tests')
-rw-r--r-- | toolkit/components/terminator/tests/xpcshell/test_terminator_advance_phases.js (renamed from toolkit/components/terminator/tests/xpcshell/test_terminator_record.js) | 42 | ||||
-rw-r--r-- | toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js | 88 | ||||
-rw-r--r-- | toolkit/components/terminator/tests/xpcshell/xpcshell.toml | 7 |
3 files changed, 15 insertions, 122 deletions
diff --git a/toolkit/components/terminator/tests/xpcshell/test_terminator_record.js b/toolkit/components/terminator/tests/xpcshell/test_terminator_advance_phases.js index 62cee636f3..42f0e3686f 100644 --- a/toolkit/components/terminator/tests/xpcshell/test_terminator_record.js +++ b/toolkit/components/terminator/tests/xpcshell/test_terminator_advance_phases.js @@ -4,14 +4,13 @@ "use strict"; -// Test that the Shutdown Terminator records durations correctly +// Test that the Shutdown Terminator advances through the shutdown phases +// correctly. const { setTimeout } = ChromeUtils.importESModule( "resource://gre/modules/Timer.sys.mjs" ); -var PATH; -var PATH_TMP; var terminator; var HEARTBEAT_MS = 100; @@ -34,8 +33,6 @@ let MeasuredDurations = []; add_task(async function init() { do_get_profile(); - PATH = PathUtils.join(PathUtils.localProfileDir, "ShutdownDuration.json"); - PATH_TMP = PATH + ".tmp"; // Initialize the terminator // (normally, this is done through the manifest file, but xpcshell @@ -44,23 +41,12 @@ add_task(async function init() { terminator = Cc["@mozilla.org/toolkit/shutdown-terminator;1"].createInstance( Ci.nsIObserver ); -}); - -var promiseShutdownDurationData = async function () { - // Wait until PATH exists. - // Timeout if it is never created. - while (true) { - if (await IOUtils.exists(PATH)) { - break; - } - - // Wait just a very short period to not increase measured values. - // Usually the file should appear almost immediately. - await new Promise(resolve => setTimeout(resolve, 50)); - } - return IOUtils.readJSON(PATH); -}; + Assert.ok( + terminator instanceof Ci.nsITerminatorTest, + "Terminator should implement nsITerminatorTest" + ); +}); var currentPhase = 0; @@ -72,13 +58,16 @@ var advancePhase = async function () { terminator.observe(null, key, null); await new Promise(resolve => setTimeout(resolve, msDuration)); - let data = await promiseShutdownDurationData(); + let data = terminator.getTicksForShutdownPhases(); - Assert.ok(KEYS[currentPhase] in data, "The file contains the expected key"); + Assert.ok( + KEYS[currentPhase] in data, + "The KEYS object contains the expected key" + ); Assert.equal( Object.keys(data).length, currentPhase + 1, - "File does not contain more durations than expected" + "KEYS object does not contain more durations than expected" ); DATA[currentPhase] = data; @@ -108,9 +97,6 @@ add_task(async function test_record() { morePhases = await advancePhase(); - await IOUtils.remove(PATH); - await IOUtils.remove(PATH_TMP); - // We measure the effective time that passed as wall-clock and include all // file IO overhead as the terminator will do so in its measurement, too. MeasuredDurations[currentPhase - 1] = Math.floor( @@ -166,6 +152,6 @@ add_task(async function test_record() { .sort() .join(", "), KEYS.sort().join(", "), - "The last file contains all expected keys" + "The KEYS object contains all expected keys" ); }); diff --git a/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js b/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js deleted file mode 100644 index 79aecd818b..0000000000 --- a/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js +++ /dev/null @@ -1,88 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// Test that the Shutdown Terminator reloads durations correctly - -const HISTOGRAMS = { - "quit-application": "SHUTDOWN_PHASE_DURATION_TICKS_QUIT_APPLICATION", - "profile-change-net-teardown": - "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_CHANGE_NET_TEARDOWN", - "profile-change-teardown": - "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_CHANGE_TEARDOWN", - "profile-before-change": - "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_BEFORE_CHANGE", - "profile-before-change-qm": - "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_BEFORE_CHANGE_QM", - "xpcom-will-shutdown": "SHUTDOWN_PHASE_DURATION_TICKS_XPCOM_WILL_SHUTDOWN", - "xpcom-shutdown": "SHUTDOWN_PHASE_DURATION_TICKS_XPCOM_SHUTDOWN", -}; - -let PATH; - -add_setup(async function init() { - do_get_profile(); - PATH = PathUtils.join(PathUtils.localProfileDir, "ShutdownDuration.json"); -}); - -add_task(async function test_reload() { - info("Forging data"); - let data = {}; - let telemetrySnapshots = Services.telemetry.getSnapshotForHistograms( - "main", - false /* clear */ - ).parent; - let i = 0; - for (let k of Object.keys(HISTOGRAMS)) { - let id = HISTOGRAMS[k]; - data[k] = i++; - Assert.equal( - telemetrySnapshots[id] || undefined, - undefined, - "Histogram " + id + " is empty" - ); - } - - // Extra fields that nsTerminator reports that we do not have histograms for. - data["xpcom-shutdown-threads"] = 123; - data.XPCOMShutdownFinal = 456; - data.CCPostLastCycleCollection = 789; - - await IOUtils.writeJSON(PATH, data); - - const TOPIC = "shutdown-terminator-telemetry-updated"; - - let wait = new Promise(resolve => - Services.obs.addObserver(function observer() { - info("Telemetry has been updated"); - Services.obs.removeObserver(observer, TOPIC); - resolve(); - }, TOPIC) - ); - - info("Starting nsTerminatorTelemetry"); - let tt = Cc[ - "@mozilla.org/toolkit/shutdown-terminator-telemetry;1" - ].createInstance(Ci.nsIObserver); - tt.observe(null, "profile-after-change", ""); - - info("Waiting until telemetry is updated"); - // Now wait until Telemetry is updated - await wait; - - telemetrySnapshots = Services.telemetry.getSnapshotForHistograms( - "main", - false /* clear */ - ).parent; - for (let k of Object.keys(HISTOGRAMS)) { - let id = HISTOGRAMS[k]; - info("Testing histogram " + id); - let snapshot = telemetrySnapshots[id]; - let count = 0; - for (let x of Object.values(snapshot.values)) { - count += x; - } - Assert.equal(count, 1, "We have added one item"); - } -}); diff --git a/toolkit/components/terminator/tests/xpcshell/xpcshell.toml b/toolkit/components/terminator/tests/xpcshell/xpcshell.toml index cb328ca2c8..67cc36f265 100644 --- a/toolkit/components/terminator/tests/xpcshell/xpcshell.toml +++ b/toolkit/components/terminator/tests/xpcshell/xpcshell.toml @@ -1,15 +1,10 @@ [DEFAULT] head = "" -["test_terminator_record.js"] +["test_terminator_advance_phases.js"] skip-if = [ "debug", "asan", # Disabled by bug 1242084, bug 1255484 will enable it again "ccov", # Bug 1607583 tracks the ccov failure "tsan", # Bug 1683730 made this timeout for tsan. ] -run-sequentially = "very high failure rate in parallel" - -["test_terminator_reload.js"] -skip-if = ["os == 'android'"] -run-sequentially = "very high failure rate in parallel" |