mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
test: improve flaky test-listen-fd-ebadf.js
Find an invalid file descriptor rather than assuming 42 will be invalid. PR-URL: https://github.com/nodejs/node/pull/17797 Fixes: https://github.com/nodejs/node/issues/17762 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
1 parent
dce7d7fc64
commit
112b655107
1 file changed
+13
-1
@@ -21,12 +21,24 @@
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const net = require('net');
|
||||
|
||||
net.createServer(common.mustNotCall()).listen({ fd: 2 })
|
||||
.on('error', common.mustCall(onError));
|
||||
net.createServer(common.mustNotCall()).listen({ fd: 42 })
|
||||
|
||||
let invalidFd = 2;
|
||||
|
||||
// Get first known bad file descriptor.
|
||||
try {
|
||||
while (fs.fstatSync(++invalidFd));
|
||||
} catch (e) {
|
||||
// do nothing; we now have an invalid fd
|
||||
}
|
||||
|
||||
net.createServer(common.mustNotCall()).listen({ fd: invalidFd })
|
||||
.on('error', common.mustCall(onError));
|
||||
|
||||
function onError(ex) {
|
||||
|
||||
Reference in new issue
Block a user