未验证 提交 c3618578 编写于 作者: A Ankit Jain 提交者: GitHub

[wasm][nodejs] Ensure that stdout/stderr have been flushed out before exiting (#70416)

When the results xml is large, and we are writing the base64
representation in one line, `node` can exit before all the output gets
flushed out. This results in xharness getting an incomplete
`STARTRESULTXML <len> <base64> ... ` with missing `ENDRESULTXML`, thus
no `testResults.xml` is generated.

This can be seen in the case of `Microsoft.Extensions.Primitives.Tests`
which has xml ~140KB, and `System.Memory.Tests` which has a xml ~13MB.

So, wait for the two streams to be flushed out, with a timeout of 3secs.

- use the `drain` event only if `stream.write('')` returns `false`
* Address review feedback @kg, @maraf
上级 ed1595e2
......@@ -105,7 +105,30 @@ function set_exit_code(exit_code, reason) {
}
} else if (App && App.INTERNAL) {
App.INTERNAL.mono_wasm_exit(exit_code);
if (is_node) {
let _flush = function(_stream) {
return new Promise((resolve, reject) => {
if (!_stream.write('')) {
_stream.on('drain', () => resolve());
setTimeout(reject, 3000);
} else {
resolve();
}
});
};
let stderrFlushed = _flush(process.stderr);
let stdoutFlushed = _flush(process.stdout);
Promise.all([ stdoutFlushed, stderrFlushed ])
.then(
() => App.INTERNAL.mono_wasm_exit(exit_code),
reason => {
console.error(`flushing std* streams failed: ${reason}`);
App.INTERNAL.mono_wasm_exit(123);
});
} else {
App.INTERNAL.mono_wasm_exit(exit_code);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册