Skip to content

Commit

Permalink
Merge branch 'main' into kbn-140743-notifications-api-mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila committed Nov 3, 2022
2 parents 3aef92a + 1934b59 commit 439b3e7
Show file tree
Hide file tree
Showing 22 changed files with 1,732 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const journey = new Journey({
await page.waitForSelector('#dashboardListingHeading');
})

.step('Go to Ecommerce Dashboard with Saved Search only', async ({ page }) => {
.step('Go to Ecommerce Dashboard with Saved Search only', async ({ page, log }) => {
await page.click(subj('dashboardListingTitleLink-[eCommerce]-Saved-Search-Dashboard'));
await waitForVisualizations(page, 1);
await waitForVisualizations(page, log, 1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const journey = new Journey({
await page.waitForSelector('#dashboardListingHeading');
})

.step('Go to Ecommerce Dashboard with TSVB Gauge only', async ({ page }) => {
.step('Go to Ecommerce Dashboard with TSVB Gauge only', async ({ page, log }) => {
await page.click(subj('dashboardListingTitleLink-[eCommerce]-TSVB-Gauge-Only-Dashboard'));
await waitForVisualizations(page, 1);
await waitForVisualizations(page, log, 1);
});
27 changes: 27 additions & 0 deletions x-pack/plugins/task_manager/server/lib/adhoc_task_counter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { AdHocTaskCounter } from './adhoc_task_counter';

describe('AdHocTaskCounter', () => {
const counter = new AdHocTaskCounter();

afterAll(() => {
counter.reset();
});

it('increments counter', async () => {
counter.increment(10);
await expect(counter.count).toEqual(10);
});

it('resets counter', async () => {
counter.increment(10);
counter.reset();
await expect(counter.count).toEqual(0);
});
});
36 changes: 36 additions & 0 deletions x-pack/plugins/task_manager/server/lib/adhoc_task_counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/**
* Keeps track of how many tasks have been created.
*
* @export
* @class AdHocTaskCounter
*
*/
export class AdHocTaskCounter {
/**
* Gets the number of created tasks.
*/
public get count() {
return this._count;
}

private _count: number;

constructor() {
this._count = 0;
}

public increment(by: number = 1) {
this._count += by;
}

public reset() {
this._count = 0;
}
}
39 changes: 39 additions & 0 deletions x-pack/plugins/task_manager/server/lib/intervals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
secondsFromDate,
asInterval,
maxIntervalFromDate,
parseIntervalAsMinute,
} from './intervals';

let fakeTimer: sinon.SinonFakeTimers;
Expand Down Expand Up @@ -65,6 +66,44 @@ describe('taskIntervals', () => {
});
});

describe('parseIntervalAsMinute', () => {
test('it accepts intervals in the form `Nm`', () => {
expect(() => parseIntervalAsMinute(`${_.random(1, 1000)}m`)).not.toThrow();
});

test('it accepts intervals in the form `Ns`', () => {
expect(() => parseIntervalAsMinute(`${_.random(1, 1000)}s`)).not.toThrow();
});

test('it rejects 0 based intervals', () => {
expect(() => parseIntervalAsMinute('0m')).toThrow(
/Invalid interval "0m"\. Intervals must be of the form {number}m. Example: 5m/
);
expect(() => parseIntervalAsMinute('0s')).toThrow(
/Invalid interval "0s"\. Intervals must be of the form {number}m. Example: 5m/
);
});

test('it rejects intervals are not of the form `Nm` or `Ns`', () => {
expect(() => parseIntervalAsMinute(`5m 2s`)).toThrow(
/Invalid interval "5m 2s"\. Intervals must be of the form {number}m. Example: 5m/
);
expect(() => parseIntervalAsMinute(`hello`)).toThrow(
/Invalid interval "hello"\. Intervals must be of the form {number}m. Example: 5m/
);
});

test('returns an interval as m', () => {
expect(parseIntervalAsMinute('5s')).toEqual(5 / 60);
expect(parseIntervalAsMinute('15s')).toEqual(15 / 60);
expect(parseIntervalAsMinute('20m')).toEqual(20);
expect(parseIntervalAsMinute('61m')).toEqual(61);
expect(parseIntervalAsMinute('90m')).toEqual(90);
expect(parseIntervalAsMinute('2h')).toEqual(2 * 60);
expect(parseIntervalAsMinute('9d')).toEqual(9 * 60 * 24);
});
});

describe('parseIntervalAsMillisecond', () => {
test('it accepts intervals in the form `Nm`', () => {
expect(() => parseIntervalAsMillisecond(`${_.random(1, 1000)}m`)).not.toThrow();
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/task_manager/server/lib/intervals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const parseIntervalAsSecond = memoize((interval: Interval): number => {
return Math.round(parseIntervalAsMillisecond(interval) / 1000);
});

export const parseIntervalAsMinute = memoize((interval: Interval): number => {
return parseIntervalAsMillisecond(interval) / (1000 * 60);
});

export const parseIntervalAsMillisecond = memoize((interval: Interval): number => {
const numericAsStr: string = interval.slice(0, -1);
const numeric: number = parseInt(numericAsStr, 10);
Expand Down
Loading

0 comments on commit 439b3e7

Please sign in to comment.