mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 01:35:51 +00:00

Expose `common.refreshTmpDir()` and only call it for tests that use common.tmpDir or common.PIPE. A positive side effect is the removal of a code smell where child processes were detected by the presence of `.send()`. Now each process can decide for itself if it needs to refresh tmpDir. PR-URL: https://github.com/nodejs/io.js/pull/1954 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
'use strict';
|
|
var assert = require('assert');
|
|
var cp = require('child_process');
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
var common = require('../common');
|
|
var msg = {test: 'this'};
|
|
var nodePath = process.execPath;
|
|
var copyPath = path.join(common.tmpDir, 'node-copy.exe');
|
|
|
|
if (process.env.FORK) {
|
|
assert(process.send);
|
|
assert.equal(process.argv[0], copyPath);
|
|
process.send(msg);
|
|
process.exit();
|
|
}
|
|
else {
|
|
common.refreshTmpDir();
|
|
try {
|
|
fs.unlinkSync(copyPath);
|
|
}
|
|
catch (e) {
|
|
if (e.code !== 'ENOENT') throw e;
|
|
}
|
|
fs.writeFileSync(copyPath, fs.readFileSync(nodePath));
|
|
fs.chmodSync(copyPath, '0755');
|
|
|
|
// slow but simple
|
|
var envCopy = JSON.parse(JSON.stringify(process.env));
|
|
envCopy.FORK = 'true';
|
|
var child = require('child_process').fork(__filename, {
|
|
execPath: copyPath,
|
|
env: envCopy
|
|
});
|
|
child.on('message', common.mustCall(function(recv) {
|
|
assert.deepEqual(msg, recv);
|
|
}));
|
|
child.on('exit', common.mustCall(function(code) {
|
|
fs.unlinkSync(copyPath);
|
|
assert.equal(code, 0);
|
|
}));
|
|
}
|