Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address flaky test where instances might have different start times #57506

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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