From 101488bba2a5923feb69f27cf872b1c80b611a6e Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Apr 2024 14:44:58 +0200 Subject: [PATCH] fix tests --- .../test/functionals/http-enable.test.ts | 64 +++++++------ .../test/functionals/https-enable.test.ts | 90 +++++++++++-------- 2 files changed, 94 insertions(+), 60 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts index 9d615f53c37..ad145449783 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts @@ -227,39 +227,53 @@ describe('HttpInstrumentation', () => { }); }); - it('allows to disable outgoing request instrumentation', () => { - server.close(); - instrumentation.disable(); - - instrumentation.setConfig({ - instrumentOutgoingRequests: false, + describe('partially disable instrumentation', () => { + beforeEach(() => { + memoryExporter.reset(); }); - instrumentation.enable(); - server = http.createServer((_request, response) => { - response.end('Test Server Response'); + + afterEach(() => { + server.close(); + instrumentation.disable(); }); - server.listen(serverPort); + it('allows to disable outgoing request instrumentation', () => { + server.close(); + instrumentation.disable(); - assert.strictEqual(isWrapped(http.Server.prototype.emit), true); - assert.strictEqual(isWrapped(http.get), false); - assert.strictEqual(isWrapped(http.request), false); - }); + instrumentation.setConfig({ + instrumentOutgoingRequests: false, + }); + instrumentation.enable(); + server = http.createServer((_request, response) => { + response.end('Test Server Response'); + }); - it('allows to disable incoming request instrumentation', () => { - instrumentation.setConfig({ - instrumentIncomingRequests: false, - }); - instrumentation.enable(); - server = http.createServer((_request, response) => { - response.end('Test Server Response'); + server.listen(serverPort); + + assert.strictEqual(isWrapped(http.Server.prototype.emit), true); + assert.strictEqual(isWrapped(http.get), false); + assert.strictEqual(isWrapped(http.request), false); }); - server.listen(serverPort); + it('allows to disable incoming request instrumentation', () => { + server.close(); + instrumentation.disable(); + + instrumentation.setConfig({ + instrumentIncomingRequests: false, + }); + instrumentation.enable(); + server = http.createServer((_request, response) => { + response.end('Test Server Response'); + }); - assert.strictEqual(isWrapped(http.Server.prototype.emit), false); - assert.strictEqual(isWrapped(http.get), true); - assert.strictEqual(isWrapped(http.request), true); + server.listen(serverPort); + + assert.strictEqual(isWrapped(http.Server.prototype.emit), false); + assert.strictEqual(isWrapped(http.get), true); + assert.strictEqual(isWrapped(http.request), true); + }); }); describe('with good instrumentation options', () => { diff --git a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts index d92cfedc48f..6605194cdef 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts @@ -185,41 +185,6 @@ describe('HttpsInstrumentation', () => { }); }); - it('allows to disable outgoing request instrumentation', () => { - server.close(); - instrumentation.disable(); - - instrumentation.setConfig({ - instrumentOutgoingRequests: false, - }); - instrumentation.enable(); - server = https.createServer((_request, response) => { - response.end('Test Server Response'); - }); - - server.listen(serverPort); - - assert.strictEqual(isWrapped(http.Server.prototype.emit), true); - assert.strictEqual(isWrapped(http.get), false); - assert.strictEqual(isWrapped(http.request), false); - }); - - it('allows to disable incoming request instrumentation', () => { - instrumentation.setConfig({ - instrumentIncomingRequests: false, - }); - instrumentation.enable(); - server = https.createServer((_request, response) => { - response.end('Test Server Response'); - }); - - server.listen(serverPort); - - assert.strictEqual(isWrapped(http.Server.prototype.emit), false); - assert.strictEqual(isWrapped(http.get), true); - assert.strictEqual(isWrapped(http.request), true); - }); - describe('with good instrumentation options', () => { beforeEach(() => { memoryExporter.reset(); @@ -740,5 +705,60 @@ describe('HttpsInstrumentation', () => { req.end(); }); }); + + describe('partially disable instrumentation', () => { + beforeEach(() => { + memoryExporter.reset(); + }); + + afterEach(() => { + server.close(); + instrumentation.disable(); + }); + + it('allows to disable outgoing request instrumentation', () => { + instrumentation.setConfig({ + instrumentOutgoingRequests: false, + }); + instrumentation.enable(); + server = https.createServer( + { + key: fs.readFileSync('test/fixtures/server-key.pem'), + cert: fs.readFileSync('test/fixtures/server-cert.pem'), + }, + (request, response) => { + response.end('Test Server Response'); + } + ); + + server.listen(serverPort); + + assert.strictEqual(isWrapped(http.Server.prototype.emit), true); + assert.strictEqual(isWrapped(http.get), false); + assert.strictEqual(isWrapped(http.request), false); + }); + + it('allows to disable incoming request instrumentation', () => { + instrumentation.setConfig({ + instrumentIncomingRequests: false, + }); + instrumentation.enable(); + server = https.createServer( + { + key: fs.readFileSync('test/fixtures/server-key.pem'), + cert: fs.readFileSync('test/fixtures/server-cert.pem'), + }, + (request, response) => { + response.end('Test Server Response'); + } + ); + + server.listen(serverPort); + + assert.strictEqual(isWrapped(http.Server.prototype.emit), false); + assert.strictEqual(isWrapped(http.get), true); + assert.strictEqual(isWrapped(http.request), true); + }); + }); }); });