From 2367954d5b337c0f5c249e8f49e9f8ebe4485deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Wed, 31 Jul 2019 21:57:10 +0100 Subject: [PATCH] fixup! test: clean tmpdir on process exit Fixes for Linux open files --- test/parallel/test-fs-open-flags.js | 5 ++++- test/parallel/test-pipe-unref.js | 23 +++++++++++++++++++---- test/parallel/test-repl-history-perm.js | 5 ++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index d1fee24de690ac..62866cfb1b251d 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -94,5 +94,8 @@ if (common.isLinux || common.isOSX) { tmpdir.refresh(); const file = path.join(tmpdir.path, 'a.js'); fs.copyFileSync(fixtures.path('a.js'), file); - fs.open(file, O_DSYNC, common.mustCall(assert.ifError)); + fs.open(file, O_DSYNC, common.mustCall((err, fd) => { + assert.ifError(err); + fs.closeSync(fd); + })); } diff --git a/test/parallel/test-pipe-unref.js b/test/parallel/test-pipe-unref.js index 1e0245b5444f62..b1edc61a9b70d9 100644 --- a/test/parallel/test-pipe-unref.js +++ b/test/parallel/test-pipe-unref.js @@ -1,12 +1,27 @@ 'use strict'; const common = require('../common'); const net = require('net'); +const assert = require('assert'); +const { fork } = require('child_process'); // This test should end immediately after `unref` is called +// The pipe will stay open as Node.js completes, thus run in a child process +// so that tmpdir can be cleaned up. const tmpdir = require('../common/tmpdir'); -tmpdir.refresh(); -const s = net.Server(); -s.listen(common.PIPE); -s.unref(); +if (process.argv[2] !== 'child') { + // Parent + tmpdir.refresh(); + + // Run test + const child = fork(__filename, ['child'], { stdio: 'inherit' }); + child.on('exit', common.mustCall(function(code) { + assert.strictEqual(code, 0); + })); +} else { + // Child + const s = net.Server(); + s.listen(common.PIPE); + s.unref(); +} diff --git a/test/parallel/test-repl-history-perm.js b/test/parallel/test-repl-history-perm.js index 03ce1435d9ba4e..3db2a009eb053b 100644 --- a/test/parallel/test-repl-history-perm.js +++ b/test/parallel/test-repl-history-perm.js @@ -38,12 +38,15 @@ const replHistoryPath = path.join(tmpdir.path, '.node_repl_history'); const checkResults = common.mustCall(function(err, r) { assert.ifError(err); - r.input.end(); const stat = fs.statSync(replHistoryPath); const fileMode = stat.mode & 0o777; assert.strictEqual( fileMode, 0o600, `REPL history file should be mode 0600 but was 0${fileMode.toString(8)}`); + + // Close the REPL + r.input.emit('keypress', '', { ctrl: true, name: 'd' }); + r.input.end(); }); repl.createInternalRepl(