Skip to content

Commit

Permalink
address issue where instacnes might have different start times
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Feb 12, 2020
1 parent d00adca commit 40f6d4b
Showing 1 changed file with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import expect from '@kbn/expect';
import uuid from 'uuid';
import { omit } from 'lodash';
import { omit, mapValues } from 'lodash';
import moment from 'moment';
import { FtrProviderContext } from '../../ftr_provider_context';

Expand Down Expand Up @@ -210,59 +210,60 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
// Verify content
await testSubjects.existOrFail('alertInstancesList');

const {
alertInstances: {
['us-central']: {
meta: {
lastScheduledActions: { date },
},
},
},
} = await alerting.alerts.getAlertState(alert.id);
const { alertInstances } = await alerting.alerts.getAlertState(alert.id);

const dateOnAllInstances = moment(date)
.utc()
.format('D MMM YYYY @ HH:mm:ss');
const dateOnAllInstances = mapValues(
alertInstances,
({
meta: {
lastScheduledActions: { date },
},
}) => moment(date).utc()
);

const instancesList = await pageObjects.alertDetailsUI.getAlertInstancesList();
expect(instancesList.map(instance => omit(instance, 'duration'))).to.eql([
{
instance: 'us-central',
status: 'Active',
start: dateOnAllInstances,
start: dateOnAllInstances['us-central'].format('D MMM YYYY @ HH:mm:ss'),
},
{
instance: 'us-east',
status: 'Active',
start: dateOnAllInstances,
start: dateOnAllInstances['us-east'].format('D MMM YYYY @ HH:mm:ss'),
},
{
instance: 'us-west',
status: 'Active',
start: dateOnAllInstances,
start: dateOnAllInstances['us-west'].format('D MMM YYYY @ HH:mm:ss'),
},
]);

const durationFromInstanceTillPageLoad = moment.duration(
testBeganAt.diff(moment(date).utc())
const durationFromInstanceTillPageLoad = mapValues(dateOnAllInstances, date =>
moment.duration(testBeganAt.diff(moment(date).utc()))
);
instancesList
.map(alertInstance => alertInstance.duration.split(':').map(part => parseInt(part, 10)))
.map(([hours, minutes, seconds]) =>
moment.duration({
.map(alertInstance => ({
id: alertInstance.instance,
duration: alertInstance.duration.split(':').map(part => parseInt(part, 10)),
}))
.map(({ id, duration: [hours, minutes, seconds] }) => ({
id,
duration: moment.duration({
hours,
minutes,
seconds,
})
)
.forEach(alertInstanceDuration => {
}),
}))
.forEach(({ id, duration }) => {
// make sure the duration is within a 10 second range which is
// good enough as the alert interval is 1m, so we know it is a fresh value
expect(alertInstanceDuration.as('milliseconds')).to.greaterThan(
durationFromInstanceTillPageLoad.subtract(1000 * 10).as('milliseconds')
expect(duration.as('milliseconds')).to.greaterThan(
durationFromInstanceTillPageLoad[id].subtract(1000 * 10).as('milliseconds')
);
expect(alertInstanceDuration.as('milliseconds')).to.lessThan(
durationFromInstanceTillPageLoad.add(1000 * 10).as('milliseconds')
expect(duration.as('milliseconds')).to.lessThan(
durationFromInstanceTillPageLoad[id].add(1000 * 10).as('milliseconds')
);
});
});
Expand Down

0 comments on commit 40f6d4b

Please sign in to comment.