summaryrefslogtreecommitdiff
path: root/test/common/index.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-02-19 17:36:59 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-02-22 22:08:52 +0800
commitacf2fd39f7461b36d895582e7b7d7a8b3be03eff (patch)
tree61f7d1cea9e0298a300e93ca7807585910e12612 /test/common/index.js
parent13637d23f7a2667c2f9abfe2c1a44d6941e10681 (diff)
downloadandroid-node-v8-acf2fd39f7461b36d895582e7b7d7a8b3be03eff.tar.gz
android-node-v8-acf2fd39f7461b36d895582e7b7d7a8b3be03eff.tar.bz2
android-node-v8-acf2fd39f7461b36d895582e7b7d7a8b3be03eff.zip
test: introduce common.runWithInvalidFD()
This provides a more reliable way to get a fd that can be used to tirgger EBADF. PR-URL: https://github.com/nodejs/node/pull/18864 Fixes: https://github.com/nodejs/node/issues/18820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/common/index.js')
-rw-r--r--test/common/index.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/common/index.js b/test/common/index.js
index 54b146814a..10fd637af9 100644
--- a/test/common/index.js
+++ b/test/common/index.js
@@ -816,6 +816,19 @@ function restoreWritable(name) {
delete process[name].writeTimes;
}
+exports.runWithInvalidFD = function(func) {
+ let fd = 1 << 30;
+ // Get first known bad file descriptor. 1 << 30 is usually unlikely to
+ // be an valid one.
+ try {
+ while (fs.fstatSync(fd--) && fd > 0);
+ } catch (e) {
+ return func(fd);
+ }
+
+ exports.printSkipMessage('Could not generate an invalid fd');
+};
+
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
exports.restoreStdout = restoreWritable.bind(null, 'stdout');