Skip to content

Commit

Permalink
fixup! test: clean tmpdir on process exit
Browse files Browse the repository at this point in the history
Fixes for Linux open files
  • Loading branch information
joaocgreis committed Jul 31, 2019
1 parent 3189416 commit 2367954
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
}
23 changes: 19 additions & 4 deletions test/parallel/test-pipe-unref.js
Original file line number Diff line number Diff line change
@@ -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();
}
5 changes: 4 additions & 1 deletion test/parallel/test-repl-history-perm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2367954

Please sign in to comment.