test: move firstInvalidFD() out of common module
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 <targos@protonmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
ddf3655f2b
commit
40bab30067
@ -851,12 +851,3 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
|
|||||||
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
|
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
|
||||||
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
|
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
|
||||||
exports.restoreStderr = restoreWritable.bind(null, 'stderr');
|
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;
|
|
||||||
};
|
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
if (!common.hasCrypto)
|
if (!common.hasCrypto)
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
const http2 = require('http2');
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const fs = require('fs');
|
||||||
|
const http2 = require('http2');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
NGHTTP2_INTERNAL_ERROR
|
NGHTTP2_INTERNAL_ERROR
|
||||||
@ -18,7 +20,16 @@ const errorCheck = common.expectsError({
|
|||||||
|
|
||||||
const server = http2.createServer();
|
const server = http2.createServer();
|
||||||
server.on('stream', (stream) => {
|
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));
|
stream.on('error', common.mustCall(errorCheck));
|
||||||
});
|
});
|
||||||
server.listen(0, () => {
|
server.listen(0, () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user