diff options
author | Rich Trott <rtrott@gmail.com> | 2017-12-20 13:59:14 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-12-21 15:12:44 -0800 |
commit | 1d8789188fa156d5eb75c155f6c648c2bd96b842 (patch) | |
tree | 7d4313234a64c38a9f80aa636c5584dead57ba4f /test/parallel/test-listen-fd-ebadf.js | |
parent | c90b10d9f2ddc6f9b57036d51d7b0d67df92389a (diff) | |
download | android-node-v8-1d8789188fa156d5eb75c155f6c648c2bd96b842.tar.gz android-node-v8-1d8789188fa156d5eb75c155f6c648c2bd96b842.tar.bz2 android-node-v8-1d8789188fa156d5eb75c155f6c648c2bd96b842.zip |
test: improve flaky test-listen-fd-ebadf.js
Find an invalid file descriptor rather than assuming 42 will be invalid.
PR-URL: https://github.com/nodejs/node/pull/17797
Fixes: https://github.com/nodejs/node/issues/17762
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-listen-fd-ebadf.js')
-rw-r--r-- | test/parallel/test-listen-fd-ebadf.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/test/parallel/test-listen-fd-ebadf.js b/test/parallel/test-listen-fd-ebadf.js index 0f09d386d5..564dea7f95 100644 --- a/test/parallel/test-listen-fd-ebadf.js +++ b/test/parallel/test-listen-fd-ebadf.js @@ -21,12 +21,24 @@ 'use strict'; const common = require('../common'); + const assert = require('assert'); +const fs = require('fs'); const net = require('net'); net.createServer(common.mustNotCall()).listen({ fd: 2 }) .on('error', common.mustCall(onError)); -net.createServer(common.mustNotCall()).listen({ fd: 42 }) + +let invalidFd = 2; + +// Get first known bad file descriptor. +try { + while (fs.fstatSync(++invalidFd)); +} catch (e) { + // do nothing; we now have an invalid fd +} + +net.createServer(common.mustNotCall()).listen({ fd: invalidFd }) .on('error', common.mustCall(onError)); function onError(ex) { |