Bug 1754572 - Add a delayed kill test r=nika

Differential Revision: https://phabricator.services.mozilla.com/D138483
This commit is contained in:
Alexandre Lissy 2022-02-11 20:48:58 +00:00
Родитель 8dc1a247ac
Коммит d7db5c7bd5
2 изменённых файлов: 68 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,7 @@ support-files =
skip-if = !crashreporter
[browser_utility_clean_shutdown.js]
[browser_utility_hard_kill.js]
[browser_utility_hard_kill_delayed.js] # bug 1754572: we really want hard_kill to be rust before hard_kill_delayed
[browser_utility_memoryReport.js]
skip-if = tsan # bug 1754554
[browser_utility_profiler.js]

Просмотреть файл

@ -0,0 +1,67 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var utilityPid = undefined;
add_task(async () => {
const utilityProcessTest = Cc[
"@mozilla.org/utility-process-test;1"
].createInstance(Ci.nsIUtilityProcessTest);
await utilityProcessTest
.startProcess()
.then(async pid => {
utilityPid = pid;
ok(true, "Could start Utility process: " + pid);
})
.catch(async () => {
ok(false, "Cannot start Utility process?");
});
});
add_task(async () => {
SimpleTest.expectChildProcessCrash();
const utilityProcessGone = TestUtils.topicObserved("ipc:utility-shutdown");
info("Hard kill Utility Process");
const ProcessTools = Cc["@mozilla.org/processtools-service;1"].getService(
Ci.nsIProcessToolsService
);
// Here we really want to exercise the fact that kill() might not be done
// right now but a bit later, and we should wait for the process to be dead
// before considering the test is finished.
//
// Without this, we get into bug 1754572 (where there was no setTimeout nor
// the wait) where the kill() operation ends up really killing the child a
// bit after the current test has been finished ; unfortunately, this happened
// right after the next test, browser_utility_memoryReport.js did start and
// even worse, after it thought it had started a new utility process. We were
// in fact re-using the one we started here, and when we wanted to query its
// pid in the browser_utility_memoryReport.js then the kill() happened, so
// no more process and the test intermittently failed.
//
// The timeout value of 50ms should be long enough to allow the test to finish
// and the next one to start and get a reference on the process we launched,
// and yet allow us to kill the process in the middle of the next test. Higher
// values would allow browser_utility_memoryReport.js to complete without
// reproducing the issue (both locally and on try).
//
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(() => {
ProcessTools.kill(utilityPid);
}, 50);
info(`Waiting for utility process ${utilityPid} to go away.`);
let [subject, data] = await utilityProcessGone;
ok(
subject instanceof Ci.nsIPropertyBag2,
"Subject needs to be a nsIPropertyBag2 to clean up properly"
);
is(
parseInt(data, 10),
utilityPid,
`Should match the crashed PID ${utilityPid} with ${data}`
);
});