From b3c436552730da66f19627bd1136c2f5174b38fe 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. Fixes: https://github.com/nodejs/node/issues/17762 --- 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) {