Skip to content

Commit

Permalink
test: move firstInvalidFD() out of common module
Browse files Browse the repository at this point in the history
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: #17781
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott authored and targos committed Mar 24, 2018
1 parent 8e69026 commit c6b993b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 0 additions & 10 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
15 changes: 13 additions & 2 deletions test/parallel/test-http2-respond-file-fd-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, () => {
Expand Down

0 comments on commit c6b993b

Please sign in to comment.