Skip to content

Commit 3d40ad4

Browse files
committed
fix(node): Fix for manual tests in node
Set port to 0 for servers in node manual tests so that an empty port is assigned rather then explicitly picking a port that might be taken. Also, add explicit server close statement to ensure that server is closed diff --git a/packages/node/test/manual/apm-transaction/main.js b/packages/node/test/manual/apm-transaction/main.js index 1ec9723..74c679a 100644 --- a/packages/node/test/manual/apm-transaction/main.js +++ b/packages/node/test/manual/apm-transaction/main.js @@ -105,8 +105,9 @@ app.get('/trace', async (_req, res, next) => { app.use(Tracing.finish()); app.use(Sentry.Handlers.errorHandler()); -const server = app.listen(1231, () => { - http.get('http://localhost:1231/trace', res => { +const server = app.listen(0, () => { + const port = server.address().port; + http.get(`http://localhost:${port}/trace`, res => { server.close(); }); }); diff --git a/packages/node/test/manual/express-scope-separation/start.js b/packages/node/test/manual/express-scope-separation/start.js index 5d1dd48..cede112 100644 --- a/packages/node/test/manual/express-scope-separation/start.js +++ b/packages/node/test/manual/express-scope-separation/start.js @@ -18,6 +18,7 @@ class DummyTransport { if (!remaining) { console.error('SUCCESS: All scopes contain correct tags'); + server.close(); process.exit(0); } @@ -83,8 +84,9 @@ app.get('/baz', req => { app.use(Sentry.Handlers.errorHandler()); -app.listen(1121); - -http.get('http://localhost:1121/foo'); -http.get('http://localhost:1121/bar'); -http.get('http://localhost:1121/baz'); +const server = app.listen(0, () => { + const port = server.address().port; + http.get(`http://localhost:${port}/foo`); + http.get(`http://localhost:${port}/bar`); + http.get(`http://localhost:${port}/baz`); +}); diff --git a/packages/node/test/manual/memory-leak/express-patient.js b/packages/node/test/manual/memory-leak/express-patient.js index 15cc382..430a07e 100644 --- a/packages/node/test/manual/memory-leak/express-patient.js +++ b/packages/node/test/manual/memory-leak/express-patient.js @@ -146,7 +146,8 @@ app.use((err, req, res, next) => { return res.status(500).send('oh no there was an error: ' + err.message); }); -const server = app.listen(5140, () => { - process._rawDebug('patient is waiting to be poked on port 5140'); +const server = app.listen(0, () => { + const port = server.address().port; + process._rawDebug(`patient is waiting to be poked on port ${port}`); memwatch.gc(); });
1 parent 10938a7 commit 3d40ad4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

packages/node/test/manual/apm-transaction/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ app.get('/trace', async (_req, res, next) => {
105105
app.use(Tracing.finish());
106106
app.use(Sentry.Handlers.errorHandler());
107107

108-
const server = app.listen(1231, () => {
109-
http.get('http://localhost:1231/trace', res => {
108+
const server = app.listen(0, () => {
109+
const port = server.address().port;
110+
http.get(`http://localhost:${port}/trace`, res => {
110111
server.close();
111112
});
112113
});

packages/node/test/manual/express-scope-separation/start.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DummyTransport {
1818

1919
if (!remaining) {
2020
console.error('SUCCESS: All scopes contain correct tags');
21+
server.close();
2122
process.exit(0);
2223
}
2324

@@ -83,8 +84,9 @@ app.get('/baz', req => {
8384

8485
app.use(Sentry.Handlers.errorHandler());
8586

86-
app.listen(1121);
87-
88-
http.get('http://localhost:1121/foo');
89-
http.get('http://localhost:1121/bar');
90-
http.get('http://localhost:1121/baz');
87+
const server = app.listen(0, () => {
88+
const port = server.address().port;
89+
http.get(`http://localhost:${port}/foo`);
90+
http.get(`http://localhost:${port}/bar`);
91+
http.get(`http://localhost:${port}/baz`);
92+
});

packages/node/test/manual/memory-leak/express-patient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ app.use((err, req, res, next) => {
146146
return res.status(500).send('oh no there was an error: ' + err.message);
147147
});
148148

149-
const server = app.listen(5140, () => {
150-
process._rawDebug('patient is waiting to be poked on port 5140');
149+
const server = app.listen(0, () => {
150+
const port = server.address().port;
151+
process._rawDebug(`patient is waiting to be poked on port ${port}`);
151152
memwatch.gc();
152153
});

0 commit comments

Comments
 (0)