Skip to content
Permalink
Browse files

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 <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>
  • Loading branch information
Trott committed Dec 21, 2017
1 parent c90b10d commit 1d8789188fa156d5eb75c155f6c648c2bd96b842
Showing with 13 additions and 1 deletion.
  1. +13 −1 test/parallel/test-listen-fd-ebadf.js
@@ -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) {

0 comments on commit 1d87891

Please sign in to comment.
You can’t perform that action at this time.