Skip to content

Commit

Permalink
Fix functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Apr 21, 2022
1 parent 907c5c8 commit e6ff58a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

const NANOS_IN_MILLIS = 1000 * 1000;
const NANOS_IN_MILLIS = BigInt(1000 * 1000);

// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -538,13 +538,14 @@ export default function ({ getService }: FtrProviderContext) {
const executeEventEnd = Date.parse(executeEvent?.event?.end || 'undefined');
const dateNow = Date.now();

expect(typeof duration).to.be('number');
expect(typeof duration).to.be('string');
expect(executeEventStart).to.be.ok();
expect(startExecuteEventStart).to.equal(executeEventStart);
expect(executeEventEnd).to.be.ok();

const durationDiff = Math.abs(
Math.round(duration! / NANOS_IN_MILLIS) - (executeEventEnd - executeEventStart)
Math.round(Number(BigInt(duration!) / NANOS_IN_MILLIS)) -
(executeEventEnd - executeEventStart)
);

// account for rounding errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getEventLog,
} from '../../../common/lib';

const NANOS_IN_MILLIS = 1000 * 1000;
const NANOS_IN_MILLIS = BigInt(1000 * 1000);

// eslint-disable-next-line import/no-default-export
export default function alertTests({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -1303,12 +1303,12 @@ instanceStateValue: true
const eventEnd = Date.parse(event?.event?.end || 'undefined');
const dateNow = Date.now();

expect(typeof duration).to.be('number');
expect(typeof duration).to.be('string');
expect(eventStart).to.be.ok();
expect(eventEnd).to.be.ok();

const durationDiff = Math.abs(
Math.round(duration! / NANOS_IN_MILLIS) - (eventEnd - eventStart)
Math.round(Number(BigInt(duration!) / NANOS_IN_MILLIS)) - (eventEnd - eventStart)
);

// account for rounding errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

const NANOS_IN_MILLIS = 1000 * 1000;
const NANOS_IN_MILLIS = BigInt(1000 * 1000);

// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -372,13 +372,14 @@ export default function ({ getService }: FtrProviderContext) {
const executeEventEnd = Date.parse(executeEvent?.event?.end || 'undefined');
const dateNow = Date.now();

expect(typeof duration).to.be('number');
expect(typeof duration).to.be('string');
expect(executeEventStart).to.be.ok();
expect(startExecuteEventStart).to.equal(executeEventStart);
expect(executeEventEnd).to.be.ok();

const durationDiff = Math.abs(
Math.round(duration! / NANOS_IN_MILLIS) - (executeEventEnd - executeEventStart)
Math.round(Number(BigInt(duration!) / NANOS_IN_MILLIS)) -
(executeEventEnd - executeEventStart)
);

// account for rounding errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

const NANOS_IN_MILLIS = 1000 * 1000;
const NANOS_IN_MILLIS = BigInt(1000 * 1000);

// eslint-disable-next-line import/no-default-export
export default function eventLogTests({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -786,14 +786,14 @@ export function validateEvent(event: IValidatedEvent, params: ValidateEventLogPa
const dateNow = Date.now();

if (duration !== undefined) {
expect(typeof duration).to.be('number');
expect(typeof duration).to.be('string');
expect(eventStart).to.be.ok();

if (shouldHaveEventEnd !== false) {
expect(eventEnd).to.be.ok();

const durationDiff = Math.abs(
Math.round(duration! / NANOS_IN_MILLIS) - (eventEnd - eventStart)
Math.round(Number(BigInt(duration!) / NANOS_IN_MILLIS)) - (eventEnd - eventStart)
);

// account for rounding errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function eventLogAlertTests({ getService }: FtrProviderContext) {
const currentAlertSpan: {
alertId?: string;
start?: string;
durationToDate?: number;
durationToDate?: string;
} = {};
for (let i = 0; i < instanceEvents.length; ++i) {
switch (instanceEvents[i]?.event?.action) {
Expand All @@ -110,10 +110,11 @@ export default function eventLogAlertTests({ getService }: FtrProviderContext) {
expect(instanceEvents[i]?.event?.start).to.equal(currentAlertSpan.start);
expect(instanceEvents[i]?.event?.end).to.be(undefined);

if (instanceEvents[i]?.event?.duration! !== 0) {
expect(instanceEvents[i]?.event?.duration! > currentAlertSpan.durationToDate!).to.be(
true
);
if (instanceEvents[i]?.event?.duration! !== '0') {
expect(
BigInt(instanceEvents[i]?.event?.duration!) >
BigInt(currentAlertSpan.durationToDate!)
).to.be(true);
}
currentAlertSpan.durationToDate = instanceEvents[i]?.event?.duration;
break;
Expand All @@ -125,7 +126,7 @@ export default function eventLogAlertTests({ getService }: FtrProviderContext) {
expect(
new Date(instanceEvents[i]?.event?.end!).valueOf() -
new Date(instanceEvents[i]?.event?.start!).valueOf()
).to.equal(instanceEvents[i]?.event?.duration! / 1000 / 1000);
).to.equal(Number(BigInt(instanceEvents[i]?.event?.duration!) / BigInt(1000000)));
break;
}
}
Expand Down

0 comments on commit e6ff58a

Please sign in to comment.