Skip to content

Commit 112b655

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 dce7d7f commit 112b655

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
@@ -21,12 +21,24 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
2425
const assert = require('assert');
26+
const fs = require('fs');
2527
const net = require('net');
2628

2729
net.createServer(common.mustNotCall()).listen({ fd: 2 })
2830
.on('error', common.mustCall(onError));
29-
net.createServer(common.mustNotCall()).listen({ fd: 42 })
31+
32+
let invalidFd = 2;
33+
34+
// Get first known bad file descriptor.
35+
try {
36+
while (fs.fstatSync(++invalidFd));
37+
} catch (e) {
38+
// do nothing; we now have an invalid fd
39+
}
40+
41+
net.createServer(common.mustNotCall()).listen({ fd: invalidFd })
3042
.on('error', common.mustCall(onError));
3143

3244
function onError(ex) {

0 commit comments

Comments
 (0)