Skip to content

Commit

Permalink
[Bug] Fix randomly failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Oct 7, 2022
1 parent 7390e1d commit 6806ecb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
3 changes: 2 additions & 1 deletion AISKU/Tests/Unit/src/ApplicationInsightsDeprecatedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Snippet } from "../../../src/Initialization";
import { Sender } from "@microsoft/applicationinsights-channel-js";
import { SinonSpy } from "sinon";
import { AITestClass, Assert, PollingAssert } from "@microsoft/ai-test-framework";
import { dumpObj } from "@microsoft/applicationinsights-core-js";

export class ApplicationInsightsDeprecatedTests extends AITestClass {
private static readonly _instrumentationKey = 'b7170927-2d1c-44f1-acec-59f4e1751c11';
Expand Down Expand Up @@ -142,7 +143,7 @@ export class ApplicationInsightsDeprecatedTests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/SnippetInitialization.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Sender } from "@microsoft/applicationinsights-channel-js";
import { SinonSpy } from "sinon";
import { AITestClass, Assert, PollingAssert } from "@microsoft/ai-test-framework";
import { createSnippetV5 } from "./testSnippet";
import { hasOwnProperty, isNotNullOrUndefined, ITelemetryItem, objForEachKey } from "@microsoft/applicationinsights-core-js";
import { dumpObj, hasOwnProperty, isNotNullOrUndefined, ITelemetryItem, objForEachKey } from "@microsoft/applicationinsights-core-js";
import { ContextTagKeys, DistributedTracingModes, IConfig, IDependencyTelemetry, RequestHeaders, Util } from "@microsoft/applicationinsights-common";
import { getGlobal } from "@microsoft/applicationinsights-shims";
import { TelemetryContext } from "@microsoft/applicationinsights-properties-js";
Expand Down Expand Up @@ -904,7 +904,7 @@ export class SnippetInitializationTests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/SnippetLegacyInitialization.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Sender } from "@microsoft/applicationinsights-channel-js";
import { createLegacySnippet } from "./testLegacySnippet";
import { SinonSpy } from "sinon";
import { AITestClass, Assert, PollingAssert } from "@microsoft/ai-test-framework";
import { hasOwnProperty, isNotNullOrUndefined } from "@microsoft/applicationinsights-core-js";
import { dumpObj, hasOwnProperty, isNotNullOrUndefined } from "@microsoft/applicationinsights-core-js";

function getBasicLegacySnippetConfig() {
return {
Expand Down Expand Up @@ -342,7 +342,7 @@ export class SnippetLegacyInitializationTests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/applicationinsights.e2e.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SinonSpy } from 'sinon';
import { ApplicationInsights, IApplicationInsights } from '../../../src/applicationinsights-web'
import { Sender } from '@microsoft/applicationinsights-channel-js';
import { IDependencyTelemetry, ContextTagKeys, Util, Event, Trace, Exception, Metric, PageView, PageViewPerformance, RemoteDependencyData, DistributedTracingModes, RequestHeaders, IAutoExceptionTelemetry } from '@microsoft/applicationinsights-common';
import { AppInsightsCore, ITelemetryItem, getGlobal } from "@microsoft/applicationinsights-core-js";
import { AppInsightsCore, ITelemetryItem, getGlobal, dumpObj } from "@microsoft/applicationinsights-core-js";
import { TelemetryContext } from '@microsoft/applicationinsights-properties-js';


Expand Down Expand Up @@ -973,7 +973,7 @@ export class ApplicationInsightsTests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions AISKU/Tests/Unit/src/sender.e2e.tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApplicationInsights, IApplicationInsights } from '../../../src/applicationinsights-web'
import { Sender } from '@microsoft/applicationinsights-channel-js';
import { Util } from '@microsoft/applicationinsights-common';
import { getJSON } from '@microsoft/applicationinsights-core-js';
import { dumpObj, getJSON } from '@microsoft/applicationinsights-core-js';
import { SinonSpy } from 'sinon';
import { Assert, AITestClass, PollingAssert} from "@microsoft/ai-test-framework"

Expand Down Expand Up @@ -174,7 +174,7 @@ export class SenderE2ETests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion AISKU/Tests/Unit/src/validate.e2e.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApplicationInsights, IApplicationInsights } from '../../../src/applicat
import { Sender } from '@microsoft/applicationinsights-channel-js';
import { SinonSpy } from 'sinon';
import { AITestClass, Assert, PollingAssert } from '@microsoft/ai-test-framework';
import { dumpObj } from '@microsoft/applicationinsights-core-js';

export class ValidateE2ETests extends AITestClass {
private readonly _instrumentationKey = 'b7170927-2d1c-44f1-acec-59f4e1751c11';
Expand Down Expand Up @@ -153,7 +154,7 @@ export class ValidateE2ETests extends AITestClass {
Assert.ok(isValidCallCount, "logging spy was called 0 time(s)");
if (!isValidCallCount) {
while (this.loggingSpy.args.length) {
Assert.ok(false, "[warning thrown]: " + this.loggingSpy.args.pop());
Assert.ok(false, "[warning thrown]: " + dumpObj(this.loggingSpy.args.pop()));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Assert, AITestClass } from "@microsoft/ai-test-framework";
import { AppInsightsCore, IConfiguration, DiagnosticLogger, ITelemetryItem, createCookieMgr, newId, strTrim } from "@microsoft/applicationinsights-core-js";
import { AppInsightsCore, IConfiguration, DiagnosticLogger, ITelemetryItem, createCookieMgr, newId, strTrim, random32 } from "@microsoft/applicationinsights-core-js";
import PropertiesPlugin from "../../../src/PropertiesPlugin";
import { ITelemetryConfig } from "../../../src/Interfaces/ITelemetryConfig";
import { TelemetryContext } from "../../../src/TelemetryContext";
Expand Down Expand Up @@ -167,11 +167,15 @@ export class PropertiesTests extends AITestClass {

this.testCase({
name: "ai_user cookie is set with acq date and year expiration",
useFakeTimers: true,
test: () => {
// setup
var actualCookieName: string;
var actualCookieValue: string;

// Just move the time forward a random amount of time so that the cookie time is different for different test runs
this.clock.tick(random32());

var newIdStub = this.sandbox.stub(this as any, "_getNewId").callsFake(() => "newId");
var getCookieStub = this.sandbox.stub(this as any, "_getCookie").callsFake(() =>"");
var setCookieStub = this.sandbox.stub(this as any, "_setCookie").callsFake((cookieName, cookieValue) => {
Expand Down

0 comments on commit 6806ecb

Please sign in to comment.