Skip to content

Commit

Permalink
test: Env variable to specify directory for pipes
Browse files Browse the repository at this point in the history
At the uv layer pipes are connected with uv_pipe_connect.
The current spec for this method indicates that the maximum
length is limited to the size of length of
sizeof(sockaddr_un.sun_path), typically between 92 and
108 bytes. Anything longer than that just gets truncated.

The simple testsuite currently creates pipes in directories
under the directory where node was built.  In our jenkins
jobs this sometimes ends up being a deep enough path that
the path for the pipes is getting truncated.  The result
is that tests using pipes fail with errors that don't
make it obvious what the problem is.

Even if the errors were helpful, we still need a way
to avoid the truncation.

This patch adds the environment variable NODE_PIPE_DIR.
If set the tests create pipes in this directory instead of
the current defaults.  In addition the test harness is
updated to remove/delete this directory before/after
each test is run.

	modified:   test/common.js
	modified:   test/simple/test-net-pipe-connect-errors.js
	modified:   test/testpy/__init__.py
	modified:   test/simple/test-cluster-eaccess.js

Reviewed-By: Julien Gilli <[email protected]>
PR-URL: nodejs/node-v0.x-archive#9381
  • Loading branch information
mhdawson committed Mar 26, 2015
1 parent c66f8c2 commit 5dd5ce7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 6 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
exports.libDir = path.join(exports.testDir, '../lib');
exports.tmpDir = path.join(exports.testDir, 'tmp');
if (process.env.NODE_PIPE_DIR === undefined) {
exports.pipeTmpDir = exports.tmpDir;
} else {
exports.pipeTmpDir = path.join(process.env.NODE_PIPE_DIR, 'NodePipeTmp');
}
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;

exports.opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
if (process.platform === 'win32') {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
exports.opensslCli += '.exe';
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
exports.PIPE = exports.pipeTmpDir + '/test.sock';
}
if (!fs.existsSync(exports.opensslCli))
exports.opensslCli = false;
Expand Down
7 changes: 6 additions & 1 deletion test/simple/test-cluster-eaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ var path = require('path');
var fs = require('fs');
var net = require('net');

var socketPath = path.join(common.fixturesDir, 'socket-path');
var socketPath = common.PIPE;
if (process.platform === 'win32') {
// for windows pipes are handled specially and we can't write to
// common.PIPE with fs.writeFileSync like we can on other platforms
socketPath = path.join(common.fixturesDir, 'socket-path');
}

if (cluster.isMaster) {
var worker = cluster.fork();
Expand Down
4 changes: 3 additions & 1 deletion test/simple/test-net-pipe-connect-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ var accessErrorFired = false;

// Test if ENOTSOCK is fired when trying to connect to a file which is not
// a socket.
var emptyTxt = path.join(common.fixturesDir, 'empty.txt');
var emptyTxt = path.join(common.pipeTmpDir, 'empty.txt');
fs.closeSync(fs.openSync(emptyTxt, 'w'));

var notSocketClient = net.createConnection(emptyTxt, function() {
assert.ok(false);
});
Expand Down
10 changes: 10 additions & 0 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,40 @@ def __init__(self, path, file, mode, context, config, additional=[]):
self.mode = mode
self.tmpdir = join(dirname(self.config.root), 'tmp')
self.additional_flags = additional
if "NODE_PIPE_DIR" in os.environ:
self.pipeTmpDir = join(os.environ["NODE_PIPE_DIR"], 'NodePipeTmp')

def AfterRun(self, result):
# delete the whole tmp dir
try:
rmtree(self.tmpdir)
if self.pipeTmpDir:
rmtree(self.pipeTmpDir);
except:
pass
# make it again.
try:
mkdir(self.tmpdir)
if self.pipeTmpDir:
mkdir(self.pipeTmpDir);
except:
pass

def BeforeRun(self):
# delete the whole tmp dir
try:
rmtree(self.tmpdir)
if self.pipeTmpDir:
rmtree(self.pipeTmpDir);
except:
pass
# make it again.
# intermittently fails on win32, so keep trying
while not os.path.exists(self.tmpdir):
try:
mkdir(self.tmpdir)
if self.pipeTmpDir:
mkdir(self.pipeTmpDir);
except:
pass

Expand Down

0 comments on commit 5dd5ce7

Please sign in to comment.