Skip to content

Commit 34f3479

Browse files
authored
test(node): Avoid using specific port for node-integration-tests (#17729)
This may flake, so just using any available port instead. Closes #17716
1 parent 8298495 commit 34f3479

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

dev-packages/node-integration-tests/suites/tracing/anthropic/scenario.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Anthropic from '@anthropic-ai/sdk';
22
import * as Sentry from '@sentry/node';
33
import express from 'express';
44

5-
const PORT = 3333;
6-
75
function startMockAnthropicServer() {
86
const app = express();
97
app.use(express.json());
@@ -50,16 +48,21 @@ function startMockAnthropicServer() {
5048
},
5149
});
5250
});
53-
return app.listen(PORT);
51+
52+
return new Promise(resolve => {
53+
const server = app.listen(0, () => {
54+
resolve(server);
55+
});
56+
});
5457
}
5558

5659
async function run() {
57-
const server = startMockAnthropicServer();
60+
const server = await startMockAnthropicServer();
5861

5962
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
6063
const client = new Anthropic({
6164
apiKey: 'mock-api-key',
62-
baseURL: `http://localhost:${PORT}/anthropic`,
65+
baseURL: `http://localhost:${server.address().port}/anthropic`,
6366
});
6467

6568
// First test: basic message completion

dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { GoogleGenAI } from '@google/genai';
22
import * as Sentry from '@sentry/node';
33
import express from 'express';
44

5-
const PORT = 3333;
6-
75
function startMockGoogleGenAIServer() {
86
const app = express();
97
app.use(express.json());
@@ -39,16 +37,20 @@ function startMockGoogleGenAIServer() {
3937
});
4038
});
4139

42-
return app.listen(PORT);
40+
return new Promise(resolve => {
41+
const server = app.listen(0, () => {
42+
resolve(server);
43+
});
44+
});
4345
}
4446

4547
async function run() {
46-
const server = startMockGoogleGenAIServer();
48+
const server = await startMockGoogleGenAIServer();
4749

4850
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
4951
const client = new GoogleGenAI({
5052
apiKey: 'mock-api-key',
51-
httpOptions: { baseUrl: `http://localhost:${PORT}` },
53+
httpOptions: { baseUrl: `http://localhost:${server.address().port}` },
5254
});
5355

5456
// Test 1: chats.create and sendMessage flow

dev-packages/node-integration-tests/suites/tracing/openai/scenario-root-span.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import express from 'express';
22
import OpenAI from 'openai';
33

4-
const PORT = 3333;
5-
64
function startMockOpenAiServer() {
75
const app = express();
86
app.use(express.json());
@@ -31,14 +29,18 @@ function startMockOpenAiServer() {
3129
},
3230
});
3331
});
34-
return app.listen(PORT);
32+
return new Promise(resolve => {
33+
const server = app.listen(0, () => {
34+
resolve(server);
35+
});
36+
});
3537
}
3638

3739
async function run() {
38-
const server = startMockOpenAiServer();
40+
const server = await startMockOpenAiServer();
3941

4042
const client = new OpenAI({
41-
baseURL: `http://localhost:${PORT}/openai`,
43+
baseURL: `http://localhost:${server.address().port}/openai`,
4244
apiKey: 'mock-api-key',
4345
});
4446

0 commit comments

Comments
 (0)