Files
sousa-gecko/toolkit/modules/subprocess/test/xpcshell/test_subprocess_polling.js
T
Rob Wu e9f22af949 Bug 1983138 - Fix use of winLastError in subprocess r=win-reviewers,gstoll
Before this patch, an attempt to read from a program that closed its
stdout would result in a never-resolving read promise on Windows.

Before this patch, an attempt to write to a program that closed its
stdin would result in a never-resolving write promise on Windows.

This patch fixes both issues by fixing the typo that prevented the
implementation from detecting errors, and adds test coverage.

Differential Revision: https://phabricator.services.mozilla.com/D261332
2025-08-26 15:01:40 +00:00

64 lines
1.7 KiB
JavaScript

"use strict";
const { getSubprocessImplForTest } = ChromeUtils.importESModule(
"resource://gre/modules/Subprocess.sys.mjs"
);
let PYTHON;
const TEST_SCRIPT = do_get_file("data_test_script.py").path;
add_setup(async () => {
PYTHON = await Subprocess.pathSearch(Services.env.get("PYTHON"));
});
// When the last process exits, we should stop polling.
// This is a regression test for bug 1982950
add_task(async function test_polling_only_when_process_is_running() {
let worker = getSubprocessImplForTest().Process.getWorker();
equal(
await worker.call("getIsPolling", []),
false,
"Initially not polling before starting a program"
);
let proc = await Subprocess.call({
command: await getRealPythonExecutable(PYTHON),
arguments: ["-u", TEST_SCRIPT, "close_pipes_and_wait_for_stdin"],
});
equal(
await worker.call("getIsPolling", []),
true,
"Is polling while process is active"
);
// Make sure that we have completed reading before exiting the program,
// to rule out pending polls from open stdout pipe. Note that we expect
// to be closed because the program closed stdout prematurely.
equal(
await proc.stdout.readString(),
"",
"Test program should have closed stdout prematurely without stdout"
);
equal(
await worker.call("getIsPolling", []),
true,
"Is still polling while process is active"
);
info("Closing stdin to trigger exit");
await proc.stdin.close();
let { exitCode } = await proc.wait();
equal(exitCode, 0, "Got expected exit code");
// This part is the regression test for bug 1982950.
equal(
await worker.call("getIsPolling", []),
false,
"Not polling when last process has exited"
);
});