From bce5a625ed607483954d8e8303312a6669073d6a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 20 Dec 2017 13:59:14 -0800 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Khaidi Chu Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- test/parallel/test-listen-fd-ebadf.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-listen-fd-ebadf.js b/test/parallel/test-listen-fd-ebadf.js index dfa99e274a76e6..ffb98a9e5eb9be 100644 --- a/test/parallel/test-listen-fd-ebadf.js +++ b/test/parallel/test-listen-fd-ebadf.js @@ -1,11 +1,23 @@ '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) {