Skip to content

Commit

Permalink
use different port
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Jul 10, 2023
1 parent 86d5e26 commit c95d42b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions packages/node/test/integrations/undici.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let hub: Hub;
let fetch: typeof FetchType;

beforeAll(async () => {
await setupTestServer();
try {
await setupTestServer();
// need to conditionally require `undici` because it's not available in Node 10
// eslint-disable-next-line @typescript-eslint/no-var-requires
fetch = require('undici').fetch;
Expand Down Expand Up @@ -51,10 +51,10 @@ conditionalTest({ min: 16 })('Undici integration', () => {
it.each([
[
'simple url',
'http://localhost:18099',
'http://localhost:18100',
undefined,
{
description: 'GET http://localhost:18099/',
description: 'GET http://localhost:18100/',
op: 'http.client',
data: expect.objectContaining({
'http.method': 'GET',
Expand All @@ -63,10 +63,10 @@ conditionalTest({ min: 16 })('Undici integration', () => {
],
[
'url with query',
'http://localhost:18099?foo=bar',
'http://localhost:18100?foo=bar',
undefined,
{
description: 'GET http://localhost:18099/',
description: 'GET http://localhost:18100/',
op: 'http.client',
data: expect.objectContaining({
'http.method': 'GET',
Expand All @@ -76,32 +76,32 @@ conditionalTest({ min: 16 })('Undici integration', () => {
],
[
'url with POST method',
'http://localhost:18099',
'http://localhost:18100',
{ method: 'POST' },
{
description: 'POST http://localhost:18099/',
description: 'POST http://localhost:18100/',
data: expect.objectContaining({
'http.method': 'POST',
}),
},
],
[
'url with POST method',
'http://localhost:18099',
'http://localhost:18100',
{ method: 'POST' },
{
description: 'POST http://localhost:18099/',
description: 'POST http://localhost:18100/',
data: expect.objectContaining({
'http.method': 'POST',
}),
},
],
[
'url with GET as default',
'http://localhost:18099',
'http://localhost:18100',
{ method: undefined },
{
description: 'GET http://localhost:18099/',
description: 'GET http://localhost:18100/',
},
],
])('creates a span with a %s', async (_: string, request, requestInit, expected) => {
Expand Down Expand Up @@ -182,11 +182,11 @@ conditionalTest({ min: 16 })('Undici integration', () => {

const undoPatch = patchUndici({ shouldCreateSpanForRequest: url => url.includes('yes') });

await fetch('http://localhost:18099/no', { method: 'POST' });
await fetch('http://localhost:18100/no', { method: 'POST' });

expect(transaction.spanRecorder?.spans.length).toBe(1);

await fetch('http://localhost:18099/yes', { method: 'POST' });
await fetch('http://localhost:18100/yes', { method: 'POST' });

expect(transaction.spanRecorder?.spans.length).toBe(2);

Expand All @@ -200,7 +200,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
hub.getScope().setSpan(transaction);

await fetch('http://localhost:18099', { method: 'POST' });
await fetch('http://localhost:18100', { method: 'POST' });

expect(transaction.spanRecorder?.spans.length).toBe(2);
const span = transaction.spanRecorder?.spans[1];
Expand All @@ -215,7 +215,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
it('attaches the sentry trace and baggage headers if there is no active span', async () => {
const scope = hub.getScope();

await fetch('http://localhost:18099', { method: 'POST' });
await fetch('http://localhost:18100', { method: 'POST' });

const propagationContext = scope.getPropagationContext();

Expand All @@ -234,15 +234,15 @@ conditionalTest({ min: 16 })('Undici integration', () => {

const undoPatch = patchUndici({ shouldCreateSpanForRequest: url => url.includes('yes') });

await fetch('http://localhost:18099/no', { method: 'POST' });
await fetch('http://localhost:18100/no', { method: 'POST' });

expect(requestHeaders['sentry-trace']).toBeDefined();
expect(requestHeaders['baggage']).toBeDefined();

expect(requestHeaders['sentry-trace'].includes(propagationContext.traceId)).toBe(true);
const firstSpanId = requestHeaders['sentry-trace'].split('-')[1];

await fetch('http://localhost:18099/yes', { method: 'POST' });
await fetch('http://localhost:18100/yes', { method: 'POST' });

expect(requestHeaders['sentry-trace']).toBeDefined();
expect(requestHeaders['baggage']).toBeDefined();
Expand All @@ -264,14 +264,14 @@ conditionalTest({ min: 16 })('Undici integration', () => {

expect(transaction.spanRecorder?.spans.length).toBe(1);

await fetch('http://localhost:18099/no', { method: 'POST' });
await fetch('http://localhost:18100/no', { method: 'POST' });

expect(transaction.spanRecorder?.spans.length).toBe(2);

expect(requestHeaders['sentry-trace']).toBeUndefined();
expect(requestHeaders['baggage']).toBeUndefined();

await fetch('http://localhost:18099/yes', { method: 'POST' });
await fetch('http://localhost:18100/yes', { method: 'POST' });

expect(transaction.spanRecorder?.spans.length).toBe(3);

Expand All @@ -290,7 +290,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
data: {
method: 'POST',
status_code: 200,
url: 'http://localhost:18099/',
url: 'http://localhost:18100/',
},
type: 'http',
timestamp: expect.any(Number),
Expand All @@ -300,7 +300,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
});
hub.bindClient(client);

await fetch('http://localhost:18099', { method: 'POST' });
await fetch('http://localhost:18100', { method: 'POST' });
});

it('adds a breadcrumb on errored request', async () => {
Expand Down Expand Up @@ -336,7 +336,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {

const undoPatch = patchUndici({ breadcrumbs: false });

await fetch('http://localhost:18099', { method: 'POST' });
await fetch('http://localhost:18100', { method: 'POST' });

undoPatch();
});
Expand Down Expand Up @@ -382,7 +382,7 @@ function setupTestServer() {
res.connection?.end();
});

testServer?.listen(18099, 'localhost');
testServer?.listen(18100);

return new Promise(resolve => {
testServer?.on('listening', resolve);
Expand Down

0 comments on commit c95d42b

Please sign in to comment.