Skip to content

Commit dd5fe3f

Browse files
author
Luca Forstner
committed
Avoid port race condition (finally pls)
1 parent b86bdb7 commit dd5fe3f

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

packages/node-integration-tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"mongodb-memory-server-global": "^7.6.3",
3535
"mysql": "^2.18.1",
3636
"nock": "^13.1.0",
37-
"pg": "^8.7.3",
38-
"portfinder": "^1.0.28"
37+
"pg": "^8.7.3"
3938
},
4039
"config": {
4140
"mongodbMemoryServer": {

packages/node-integration-tests/utils/index.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { logger, parseSemver } from '@sentry/utils';
55
import axios, { AxiosRequestConfig } from 'axios';
66
import { Express } from 'express';
77
import * as http from 'http';
8+
import { AddressInfo } from 'net';
89
import nock from 'nock';
910
import * as path from 'path';
10-
import { getPorts } from 'portfinder';
1111

1212
export type TestServerConfig = {
1313
url: string;
@@ -151,20 +151,9 @@ export class TestEnv {
151151
}
152152
});
153153

154-
getPorts(50, {}, (err, ports) => {
155-
if (err) {
156-
throw err;
157-
}
158-
159-
const port = ports.find(
160-
// Only allow ports that do not overlap with other workers - this is done to avoid race-conditions
161-
p => p % Number(process.env.TEST_WORKERS_AMOUNT) === Number(process.env.TEST_PORT_MODULO),
162-
);
163-
164-
const url = `http://localhost:${port}/test`;
165-
const server = app.listen(port, () => {
166-
resolve([server, url]);
167-
});
154+
const server = app.listen(0, () => {
155+
const url = `http://localhost:${(server.address() as AddressInfo).port}/test`;
156+
resolve([server, url]);
168157
});
169158
});
170159

packages/node-integration-tests/utils/run-tests.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ const threads = os.cpus().map(async (_, i) => {
1313
while (testPath !== undefined) {
1414
console.log(`(Worker ${i}) Running test "${testPath}"`);
1515
await new Promise(resolve => {
16-
const p = childProcess.spawn('jest', ['--runTestsByPath', testPath as string, '--forceExit'], {
17-
// These env vars are used to give workers a limited, non-overlapping set of ports to occupy.
18-
// This is done to avoid race-conditions during port reservation.
19-
env: { ...process.env, TEST_WORKERS_AMOUNT: String(os.cpus().length), TEST_PORT_MODULO: String(i) },
20-
});
16+
const p = childProcess.spawn('jest', ['--runTestsByPath', testPath as string, '--forceExit']);
2117

2218
let output = '';
2319

packages/remix/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
},
3535
"devDependencies": {
3636
"@remix-run/node": "^1.4.3",
37-
"@remix-run/react": "^1.4.3"
37+
"@remix-run/react": "^1.4.3",
38+
"portfinder": "^1.0.28"
3839
},
3940
"peerDependencies": {
4041
"@remix-run/node": "1.x",

0 commit comments

Comments
 (0)