Skip to content

Commit c6b993b

Browse files
Trotttargos
authored andcommitted
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: #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>
1 parent 8e69026 commit c6b993b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

test/common/index.js

-10
Original file line numberDiff line numberDiff line change
@@ -798,16 +798,6 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
798798
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
799799
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
800800
exports.restoreStderr = restoreWritable.bind(null, 'stderr');
801-
802-
let fd = 2;
803-
exports.firstInvalidFD = function firstInvalidFD() {
804-
// Get first known bad file descriptor.
805-
try {
806-
while (fs.fstatSync(++fd));
807-
} catch (e) {}
808-
return fd;
809-
};
810-
811801
exports.isCPPSymbolsNotMapped = exports.isWindows ||
812802
exports.isSunOS ||
813803
exports.isAIX ||

test/parallel/test-http2-respond-file-fd-invalid.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6-
const http2 = require('http2');
6+
77
const assert = require('assert');
8+
const fs = require('fs');
9+
const http2 = require('http2');
810

911
const {
1012
NGHTTP2_INTERNAL_ERROR
@@ -18,7 +20,16 @@ const errorCheck = common.expectsError({
1820

1921
const server = http2.createServer();
2022
server.on('stream', (stream) => {
21-
stream.respondWithFD(common.firstInvalidFD());
23+
let fd = 2;
24+
25+
// Get first known bad file descriptor.
26+
try {
27+
while (fs.fstatSync(++fd));
28+
} catch (e) {
29+
// do nothing; we now have an invalid fd
30+
}
31+
32+
stream.respondWithFD(fd);
2233
stream.on('error', common.mustCall(errorCheck));
2334
});
2435
server.listen(0, () => {

0 commit comments

Comments
 (0)