diff --git a/test/common/index.js b/test/common/index.js index 07ef0e65b8e..1f9c1d7822b 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -851,12 +851,3 @@ 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; -}; diff --git a/test/parallel/test-http2-respond-file-fd-invalid.js b/test/parallel/test-http2-respond-file-fd-invalid.js index 77a4d3df00d..5dbb42e4788 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, () => {