Bug 1750227 - [devtools] Register cleanup function in initBrowserToolboxTask. r=ochameau.

If a test involving the Browser Toolbox times out, the Browser Toolbox
would not close and could have impact on next tests.
In this patch we register a cleanup function to make sure we always
close the Browser Toolbox.

Differential Revision: https://phabricator.services.mozilla.com/D136096
This commit is contained in:
Nicolas Chevobbe 2022-01-19 12:51:51 +00:00
Родитель 7dfca66f06
Коммит a73d337ea1
1 изменённых файлов: 12 добавлений и 0 удалений

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

@ -172,7 +172,13 @@ async function initBrowserToolboxTask({
}
}
let destroyed = false;
async function destroy() {
// No need to do anything if `destroy` was already called.
if (destroyed) {
return null;
}
const closePromise = process._dbgProcess.wait();
evaluateExpression("gToolbox.destroy()").catch(e => {
// Ignore connection close as the toolbox destroy may destroy
@ -194,8 +200,14 @@ async function initBrowserToolboxTask({
);
await client.close();
destroyed = true;
}
// When tests involving using this task fail, the spawned Browser Toolbox is not
// destroyed and might impact the next tests (e.g. pausing the content process before
// the debugger from the content toolbox does). So make sure to cleanup everything.
registerCleanupFunction(destroy);
return {
importFunctions,
importScript,