tools,test: throw if common.PORT used in parallel tests

common.PORT should not be used in parallelized tests. (There can be a
port collision if another tests requests an arbitrary open port from the
operating system and ends up getting common.PORT before a test that uses
common.PORT uses the port.) In such a situation, throw an error.

PR-URL: https://github.com/nodejs/node/pull/17559
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
Rich Trott 2017-12-08 18:33:36 -08:00
parent 3674bee884
commit 800ce94e5c
2 changed files with 12 additions and 2 deletions

View File

@ -40,7 +40,16 @@ const noop = () => {};
// gets tools to ignore it by default or by simple rules, especially eslint.
let tmpDirName = '.tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
Object.defineProperty(exports, 'PORT', {
get: () => {
if (+process.env.TEST_PARALLEL) {
throw new Error('common.PORT cannot be used in a parallelized test');
}
return +process.env.NODE_COMMON_PORT || 12346;
},
enumerable: true
});
exports.isWindows = process.platform === 'win32';
exports.isWOW64 = exports.isWindows &&

View File

@ -532,7 +532,8 @@ class TestCase(object):
try:
result = self.RunCommand(self.GetCommand(), {
"TEST_THREAD_ID": "%d" % self.thread_id
"TEST_THREAD_ID": "%d" % self.thread_id,
"TEST_PARALLEL" : "%d" % self.parallel
})
finally:
# Tests can leave the tty in non-blocking mode. If the test runner