Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Apr 17, 2024
1 parent 32a2564 commit 101488b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});
});
});

0 comments on commit 101488b

Please sign in to comment.