Skip to content

Commit 2367954

Browse files
committed
fixup! test: clean tmpdir on process exit
Fixes for Linux open files
1 parent 3189416 commit 2367954

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

test/parallel/test-fs-open-flags.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,8 @@ if (common.isLinux || common.isOSX) {
9494
tmpdir.refresh();
9595
const file = path.join(tmpdir.path, 'a.js');
9696
fs.copyFileSync(fixtures.path('a.js'), file);
97-
fs.open(file, O_DSYNC, common.mustCall(assert.ifError));
97+
fs.open(file, O_DSYNC, common.mustCall((err, fd) => {
98+
assert.ifError(err);
99+
fs.closeSync(fd);
100+
}));
98101
}

test/parallel/test-pipe-unref.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
'use strict';
22
const common = require('../common');
33
const net = require('net');
4+
const assert = require('assert');
5+
const { fork } = require('child_process');
46

57
// This test should end immediately after `unref` is called
8+
// The pipe will stay open as Node.js completes, thus run in a child process
9+
// so that tmpdir can be cleaned up.
610

711
const tmpdir = require('../common/tmpdir');
8-
tmpdir.refresh();
912

10-
const s = net.Server();
11-
s.listen(common.PIPE);
12-
s.unref();
13+
if (process.argv[2] !== 'child') {
14+
// Parent
15+
tmpdir.refresh();
16+
17+
// Run test
18+
const child = fork(__filename, ['child'], { stdio: 'inherit' });
19+
child.on('exit', common.mustCall(function(code) {
20+
assert.strictEqual(code, 0);
21+
}));
22+
} else {
23+
// Child
24+
const s = net.Server();
25+
s.listen(common.PIPE);
26+
s.unref();
27+
}

test/parallel/test-repl-history-perm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ const replHistoryPath = path.join(tmpdir.path, '.node_repl_history');
3838
const checkResults = common.mustCall(function(err, r) {
3939
assert.ifError(err);
4040

41-
r.input.end();
4241
const stat = fs.statSync(replHistoryPath);
4342
const fileMode = stat.mode & 0o777;
4443
assert.strictEqual(
4544
fileMode, 0o600,
4645
`REPL history file should be mode 0600 but was 0${fileMode.toString(8)}`);
46+
47+
// Close the REPL
48+
r.input.emit('keypress', '', { ctrl: true, name: 'd' });
49+
r.input.end();
4750
});
4851

4952
repl.createInternalRepl(

0 commit comments

Comments
 (0)