Skip to content

Commit

Permalink
chore: adapt fastify tests to fit http instrumentation
Browse files Browse the repository at this point in the history
http instrumentation ends server spans later which results in exporting them later.
Adapt the tests to fit the new sequence.
  • Loading branch information
Flarna committed Jan 17, 2023
1 parent f24e550 commit 9047d3e
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('fastify', () => {

const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 5);
const span = spans[3];
const span = spans[2];
assert.deepStrictEqual(span.attributes, {
'fastify.type': 'request_handler',
'plugin.name': 'fastify -> @fastify/express',
Expand All @@ -168,7 +168,7 @@ describe('fastify', () => {

const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 5);
const span = spans[3];
const span = spans[2];
assert.deepStrictEqual(span.attributes, {
'fastify.type': 'request_handler',
'fastify.name': 'namedHandler',
Expand Down Expand Up @@ -220,11 +220,11 @@ describe('fastify', () => {
const spans = memoryExporter.getFinishedSpans();

assert.strictEqual(spans.length, 6);
const changedRootSpan = spans[2];
const span = spans[4];
const changedRootSpan = spans[4];
const span = spans[3];
assert.strictEqual(changedRootSpan.name, 'GET /test/:id');
assert.strictEqual(span.name, 'request handler - foo');
assert.strictEqual(span.parentSpanId, spans[3].spanContext().spanId);
assert.strictEqual(span.parentSpanId, spans[2].spanContext().spanId);
});

it('should create span for fastify express runConnect', async () => {
Expand All @@ -247,7 +247,7 @@ describe('fastify', () => {
const spans = memoryExporter.getFinishedSpans();

assert.strictEqual(spans.length, 6);
const baseSpan = spans[2];
const baseSpan = spans[4];
const span = spans[0];
assert.strictEqual(span.name, 'middleware - enhanceRequest');
assert.deepStrictEqual(span.attributes, {
Expand All @@ -263,8 +263,8 @@ describe('fastify', () => {
const spans = memoryExporter.getFinishedSpans();

assert.strictEqual(spans.length, 6);
const baseSpan = spans[3];
const span = spans[4];
const baseSpan = spans[2];
const span = spans[3];
assert.strictEqual(span.name, 'request handler - foo');
assert.deepStrictEqual(span.attributes, {
'plugin.name': 'subsystem',
Expand All @@ -280,7 +280,7 @@ describe('fastify', () => {
const spans = memoryExporter.getFinishedSpans();

assert.strictEqual(spans.length, 6);
const span = spans[2];
const span = spans[4];
assert.strictEqual(span.attributes['http.route'], '/test/:id');
});

Expand All @@ -289,7 +289,7 @@ describe('fastify', () => {

assert.strictEqual(spans.length, 6);
const baseSpan = spans[1];
const span = spans[3];
const span = spans[2];
assert.strictEqual(span.name, `middleware - ${ANONYMOUS_NAME}`);
assert.deepStrictEqual(span.attributes, {
'fastify.type': 'middleware',
Expand All @@ -306,7 +306,7 @@ describe('fastify', () => {
const spans = memoryExporter.getFinishedSpans();

assert.strictEqual(spans.length, 6);
const span = spans[4];
const span = spans[3];
assert.strictEqual(span.name, 'request handler - anonymous');
assert.deepStrictEqual(span.status, {
code: SpanStatusCode.ERROR,
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('fastify', () => {

const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 5);
const span = spans[3];
const span = spans[2];
assert.deepStrictEqual(span.attributes, {
'fastify.type': 'request_handler',
'plugin.name': 'fastify -> @fastify/express',
Expand Down Expand Up @@ -487,7 +487,7 @@ describe('fastify', () => {

const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 5);
const span = spans[3];
const span = spans[2];
assert.deepStrictEqual(span.attributes, {
'fastify.type': 'request_handler',
'plugin.name': 'fastify -> @fastify/express',
Expand Down

0 comments on commit 9047d3e

Please sign in to comment.