From 8c5fe7be4ac3a9f61bc8f887a4a47da534529ae7 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 0f09d386d5fa7c..564dea7f951a1a 100644 --- a/test/parallel/test-listen-fd-ebadf.js +++ b/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) {