From d5ada351c4b5a6c729bca01df7a502a1c80376c8 Mon Sep 17 00:00:00 2001 From: Mark Wolff Date: Mon, 27 Apr 2020 13:39:47 -0400 Subject: [PATCH] suppress noisy mongo cmds (#619) * suppress noisy mongo cmds * stabilize tests --- .../diagnostic-channel/mongodb.sub.ts | 3 +- Tests/AutoCollection/Performance.tests.ts | 50 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/AutoCollection/diagnostic-channel/mongodb.sub.ts b/AutoCollection/diagnostic-channel/mongodb.sub.ts index 1b0debdb..6309f54a 100755 --- a/AutoCollection/diagnostic-channel/mongodb.sub.ts +++ b/AutoCollection/diagnostic-channel/mongodb.sub.ts @@ -10,6 +10,7 @@ let clients: TelemetryClient[] = []; export const subscriber = (event: IStandardEvent) => { if (event.data.event.commandName === "ismaster") { // suppress noisy ismaster commands + return; } clients.forEach((client) => { const dbName = (event.data.startedData && event.data.startedData.databaseName) || "Unknown database"; @@ -39,4 +40,4 @@ export function enable(enabled: boolean, client: TelemetryClient) { channel.unsubscribe("mongodb", subscriber); } } -} \ No newline at end of file +} diff --git a/Tests/AutoCollection/Performance.tests.ts b/Tests/AutoCollection/Performance.tests.ts index 764473d5..c7f17a01 100644 --- a/Tests/AutoCollection/Performance.tests.ts +++ b/Tests/AutoCollection/Performance.tests.ts @@ -41,39 +41,43 @@ describe("AutoCollection/Performance", () => { performance1["_trackNetwork"](); performance2["_trackNetwork"](); Performance.countRequest(5000, true); - const prev1 = performance1["_lastIntervalRequestExecutionTime"]; const prev2 = performance2["_lastIntervalRequestExecutionTime"]; assert.deepEqual(prev1, prev2); assert.deepEqual(prev1, 1000 + 2000); - assert.equal(Performance["_intervalRequestExecutionTime"], 1000 + 2000 + 5000); - assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics"); - assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters"); - assert.equal(stub2.args[1][0].value, stub1.args[1][0].value); - assert.equal(stub1.args[1][0].value, (1000 + 2000) / 2, "request duration average should be 1500"); - - stub1.reset(); - stub2.reset(); + // Add to end of event loop setTimeout(() => { - // need to wait at least 1 ms so trackNetwork has valid elapsedMs value - performance1["_trackNetwork"](); - performance2["_trackNetwork"](); + assert.equal(Performance["_intervalRequestExecutionTime"], 1000 + 2000 + 5000); assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics"); assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters"); assert.equal(stub2.args[1][0].value, stub1.args[1][0].value); - assert.equal(stub1.args[1][0].value, (5000) / 1, "request duration average should be 5000"); + assert.equal(stub1.args[1][0].value, (1000 + 2000) / 2, "request duration average should be 1500"); + + stub1.reset(); + stub2.reset(); + + setTimeout(() => { + // need to wait at least 1 ms so trackNetwork has valid elapsedMs value + performance1["_trackNetwork"](); + performance2["_trackNetwork"](); + assert.equal(stub1.callCount, 2, "calls trackMetric for the 2 standard metrics"); + assert.equal(stub2.callCount, 3, "calls trackMetric for the 3 live metric counters"); + assert.equal(stub2.args[1][0].value, stub1.args[1][0].value); + assert.equal(stub1.args[1][0].value, (5000) / 1, "request duration average should be 5000"); + + appInsights.setAutoCollectPerformance(true); // set back to default of true so tests expecting the default can pass + Performance.INSTANCE.dispose(); + performance1.dispose(); + performance2.dispose(); + stub1.restore() + stub2.restore(); + setIntervalStub.restore(); + clearIntervalSpy.restore(); + done(); + }, 1); + }, 1) - appInsights.setAutoCollectPerformance(true); // set back to default of true so tests expecting the default can pass - Performance.INSTANCE.dispose(); - performance1.dispose(); - performance2.dispose(); - stub1.restore() - stub2.restore(); - setIntervalStub.restore(); - clearIntervalSpy.restore(); - done(); - }, 1); }); }); });