Skip to content

Commit

Permalink
[RAM] Fix Snooze And Unsnooze Tests (#163632)
Browse files Browse the repository at this point in the history
## Summary

Closes #159076
Unskipping snooze test
Activating unsnooze test

The problem began with setting dtstart well ahead of the test
initiation, causing the snooze period to pass before the test even
started
  • Loading branch information
jcger authored Aug 29, 2023
1 parent 924c627 commit 1543750
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
20 changes: 18 additions & 2 deletions x-pack/test/alerting_api_integration/common/lib/alert_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ interface UpdateAlwaysFiringAction {
overwrites: Record<string, any>;
}

const SNOOZE_SCHEDULE = {
rRule: {
dtstart: '2021-03-07T00:00:00.000Z',
tzid: 'UTC',
count: 1,
},
duration: 864000000,
};

export class AlertUtils {
private referenceCounter = 1;
private readonly user?: User;
Expand Down Expand Up @@ -105,7 +114,11 @@ export class AlertUtils {
const request = this.supertestWithoutAuth
.post(`${getUrlPrefix(this.space.id)}/internal/alerting/rule/${alertId}/_snooze`)
.set('kbn-xsrf', 'foo')
.set('content-type', 'application/json');
.set('content-type', 'application/json')
.send({
snooze_schedule: SNOOZE_SCHEDULE,
});

if (this.user) {
return request.auth(this.user.username, this.user.password);
}
Expand All @@ -116,7 +129,10 @@ export class AlertUtils {
const request = this.supertestWithoutAuth
.post(`${getUrlPrefix(this.space.id)}/internal/alerting/rule/${alertId}/_unsnooze`)
.set('kbn-xsrf', 'foo')
.set('content-type', 'application/json');
.set('content-type', 'application/json')
.send({
schedule_ids: [alertId],
});
if (this.user) {
return request.auth(this.user.username, this.user.password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC
loadTestFile(require.resolve('./health'));
loadTestFile(require.resolve('./excluded'));
loadTestFile(require.resolve('./snooze'));
loadTestFile(require.resolve('./unsnooze'));
loadTestFile(require.resolve('./global_execution_log'));
loadTestFile(require.resolve('./get_global_execution_kpi'));
loadTestFile(require.resolve('./get_action_error_log'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte
const objectRemover = new ObjectRemover(supertest);

after(() => objectRemover.removeAll());

for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
const alertUtils = new AlertUtils({ user, space, supertestWithoutAuth });
Expand Down Expand Up @@ -98,7 +97,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(updatedAlert.snooze_schedule).to.eql(null);
expect(updatedAlert.snooze_schedule).to.eql([]);
expect(updatedAlert.mute_all).to.eql(false);
// Ensure AAD isn't broken
await checkAAD({
Expand Down Expand Up @@ -155,7 +154,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(updatedAlert.snooze_schedule).to.eql(null);
expect(updatedAlert.snooze_schedule).to.eql([]);
expect(updatedAlert.mute_all).to.eql(false);
// Ensure AAD isn't broken
await checkAAD({
Expand Down Expand Up @@ -223,7 +222,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(updatedAlert.snooze_schedule).to.eql(null);
expect(updatedAlert.snooze_schedule).to.eql([]);
expect(updatedAlert.mute_all).to.eql(false);
// Ensure AAD isn't broken
await checkAAD({
Expand Down Expand Up @@ -291,7 +290,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(updatedAlert.snooze_schedule).to.eql(null);
expect(updatedAlert.snooze_schedule).to.eql([]);
expect(updatedAlert.mute_all).to.eql(false);
// Ensure AAD isn't broken
await checkAAD({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC
loadTestFile(require.resolve('./ephemeral'));
loadTestFile(require.resolve('./event_log_alerts'));
loadTestFile(require.resolve('./snooze'));
loadTestFile(require.resolve('./unsnooze'));
loadTestFile(require.resolve('./bulk_edit'));
loadTestFile(require.resolve('./capped_action_type'));
loadTestFile(require.resolve('./scheduled_task_id'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext
const log = getService('log');
const retry = getService('retry');

// FLAKY: https://github.com/elastic/kibana/issues/159076
describe.skip('snooze', () => {
describe('snooze', () => {
const objectRemover = new ObjectRemover(supertest);

after(() => objectRemover.removeAll());
Expand Down Expand Up @@ -354,11 +353,19 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext
.expect(200);
objectRemover.add(Spaces.space1.id, createdRule.id, 'rule', 'alerting');

const response = await alertUtils.getSnoozeRequest(createdRule.id).send({
snooze_schedule: {
...SNOOZE_SCHEDULE,
duration: 3000,
const dateStart = new Date().toISOString();
const snooze = {
...SNOOZE_SCHEDULE,
rRule: {
...SNOOZE_SCHEDULE.rRule,
// updating the dtstart to the current time because otherwise the snooze might be over already
dtstart: dateStart,
},
duration: 3000,
};

const response = await alertUtils.getSnoozeRequest(createdRule.id).send({
snooze_schedule: snooze,
});

expect(response.statusCode).to.eql(204);
Expand All @@ -369,12 +376,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext
.get(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${createdRule.id}`)
.set('kbn-xsrf', 'foo')
.expect(200);
expect(updatedAlert.snooze_schedule).to.eql([
{
...SNOOZE_SCHEDULE,
duration: 3000,
},
]);
expect(updatedAlert.snooze_schedule).to.eql([snooze]);
});
log.info('wait for snoozing to end');
await retry.try(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext

it('should handle unsnooze rule request appropriately', async () => {
const { body: createdAction } = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}}/api/actions/connector`)
.post(`${getUrlPrefix(Spaces.space1.id)}/api/actions/connector`)
.set('kbn-xsrf', 'foo')
.send({
name: 'MY action',
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext
.expect(200);
objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting');

const response = await alertUtils.getSnoozeRequest(createdAlert.id);
const response = await alertUtils.getUnsnoozeRequest(createdAlert.id);

expect(response.statusCode).to.eql(204);
expect(response.body).to.eql('');
Expand Down

0 comments on commit 1543750

Please sign in to comment.