From 40bab30067aaa464a03150529f652b853f58b024 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 19 Dec 2017 22:13:40 -0800 Subject: [PATCH] test: move firstInvalidFD() out of common module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit common.firstInvalidFD() is used in only one test. Move it out of the common module and into the one test that uses it. PR-URL: https://github.com/nodejs/node/pull/17781 Reviewed-By: Michaƫl Zasso Reviewed-By: Gireesh Punathil Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu Reviewed-By: Jon Moss Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- test/common/index.js | 9 --------- .../test-http2-respond-file-fd-invalid.js | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 11 deletions(-) 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, () => {