Skip to content

Commit

Permalink
test: improve flaky test-listen-fd-ebadf.js
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and MylesBorins committed Jan 9, 2018
1 parent dce7d7f commit 112b655
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/parallel/test-listen-fd-ebadf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 112b655

Please sign in to comment.