From 12106be01ae7b08840f775a48494b28e38d98fde Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerhard=20St=C3=B6bich?=
 <18708370+Flarna@users.noreply.github.com>
Date: Tue, 17 Jan 2023 14:55:40 +0100
Subject: [PATCH] chore: adapt fastify tests to fit http instrumentation

http instrumentation ends server spans later which results in exporting them later.
Adapt the tests to fit the new sequence.
---
 .../test/instrumentation.test.ts              | 26 +++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts
index 15570129b7..8180eeb047 100644
--- a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts
+++ b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts
@@ -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',
@@ -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',
@@ -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 () => {
@@ -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, {
@@ -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',
@@ -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');
       });
 
@@ -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',
@@ -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,
@@ -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',
@@ -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',