diff --git a/test/common/index.js b/test/common/index.js index 0e40d0be215cb8..590ffb7b00c2ba 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -798,16 +798,6 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout'); exports.hijackStderr = hijackStdWritable.bind(null, 'stderr'); exports.restoreStdout = restoreWritable.bind(null, 'stdout'); exports.restoreStderr = restoreWritable.bind(null, 'stderr'); - -let fd = 2; -exports.firstInvalidFD = function firstInvalidFD() { - // Get first known bad file descriptor. - try { - while (fs.fstatSync(++fd)); - } catch (e) {} - return fd; -}; - exports.isCPPSymbolsNotMapped = exports.isWindows || exports.isSunOS || exports.isAIX || diff --git a/test/parallel/test-http2-respond-file-fd-invalid.js b/test/parallel/test-http2-respond-file-fd-invalid.js index 77a4d3df00d0d6..5dbb42e4788a7a 100644 --- a/test/parallel/test-http2-respond-file-fd-invalid.js +++ b/test/parallel/test-http2-respond-file-fd-invalid.js @@ -3,8 +3,10 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); -const http2 = require('http2'); + const assert = require('assert'); +const fs = require('fs'); +const http2 = require('http2'); const { NGHTTP2_INTERNAL_ERROR @@ -18,7 +20,16 @@ const errorCheck = common.expectsError({ const server = http2.createServer(); server.on('stream', (stream) => { - stream.respondWithFD(common.firstInvalidFD()); + let fd = 2; + + // Get first known bad file descriptor. + try { + while (fs.fstatSync(++fd)); + } catch (e) { + // do nothing; we now have an invalid fd + } + + stream.respondWithFD(fd); stream.on('error', common.mustCall(errorCheck)); }); server.listen(0, () => {