Skip to content

Commit 5668403

Browse files
TrottMylesBorins
authored andcommitted
test: improve flaky test-listen-fd-ebadf.js
Find an invalid file descriptor rather than assuming 42 will be invalid. PR-URL: #17797 Fixes: #17762 Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent fce10f7 commit 5668403

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/parallel/test-listen-fd-ebadf.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
'use strict';
22
const common = require('../common');
3+
34
const assert = require('assert');
5+
const fs = require('fs');
46
const net = require('net');
57

68
net.createServer(common.mustNotCall()).listen({fd: 2})
79
.on('error', common.mustCall(onError));
8-
net.createServer(common.mustNotCall()).listen({fd: 42})
10+
11+
let invalidFd = 2;
12+
13+
// Get first known bad file descriptor.
14+
try {
15+
while (fs.fstatSync(++invalidFd));
16+
} catch (e) {
17+
// do nothing; we now have an invalid fd
18+
}
19+
20+
net.createServer(common.mustNotCall()).listen({ fd: invalidFd })
921
.on('error', common.mustCall(onError));
1022

1123
function onError(ex) {

0 commit comments

Comments
 (0)