Skip to content

Commit 03d2514

Browse files
TrottMylesBorins
authored andcommitted
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: #17559 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent 39e2fb6 commit 03d2514

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

test/common/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ const noop = () => {};
4040
// gets tools to ignore it by default or by simple rules, especially eslint.
4141
let tmpDirName = '.tmp';
4242

43-
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
43+
Object.defineProperty(exports, 'PORT', {
44+
get: () => {
45+
if (+process.env.TEST_PARALLEL) {
46+
throw new Error('common.PORT cannot be used in a parallelized test');
47+
}
48+
return +process.env.NODE_COMMON_PORT || 12346;
49+
},
50+
enumerable: true
51+
});
52+
4453

4554
exports.isWindows = process.platform === 'win32';
4655
exports.isWOW64 = exports.isWindows &&

tools/test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ def Run(self):
532532

533533
try:
534534
result = self.RunCommand(self.GetCommand(), {
535-
"TEST_THREAD_ID": "%d" % self.thread_id
535+
"TEST_THREAD_ID": "%d" % self.thread_id,
536+
"TEST_PARALLEL" : "%d" % self.parallel
536537
})
537538
finally:
538539
# Tests can leave the tty in non-blocking mode. If the test runner

0 commit comments

Comments
 (0)