Skip to content

Commit

Permalink
Adding retries
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Oct 4, 2022
1 parent fc8197e commit e486a24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ export default function createDisableRuleTests({ getService }: FtrProviderContex
await ruleUtils.disable(createdRule.id);

// task doc should still exist but be disabled
const taskRecord = await getScheduledTask(createdRule.scheduled_task_id);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdRule.id,
spaceId: Spaces.space1.id,
consumer: 'alertsFixture',
await retry.try(async () => {
const taskRecord = await getScheduledTask(createdRule.scheduled_task_id);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdRule.id,
spaceId: Spaces.space1.id,
consumer: 'alertsFixture',
});
expect(taskRecord.task.enabled).to.eql(false);
});
expect(taskRecord.task.enabled).to.eql(false);

// Ensure AAD isn't broken
await checkAAD({
Expand Down Expand Up @@ -195,15 +197,17 @@ export default function createDisableRuleTests({ getService }: FtrProviderContex
.expect(204);

// task doc should still exist but be disabled
const taskRecord = await getScheduledTask(createdRule.scheduled_task_id);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdRule.id,
spaceId: Spaces.space1.id,
consumer: 'alertsFixture',
await retry.try(async () => {
const taskRecord = await getScheduledTask(createdRule.scheduled_task_id);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdRule.id,
spaceId: Spaces.space1.id,
consumer: 'alertsFixture',
});
expect(taskRecord.task.enabled).to.eql(false);
});
expect(taskRecord.task.enabled).to.eql(false);

// Ensure AAD isn't broken
await checkAAD({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function createRunSoonTests({ getService }: FtrProviderContext) {

it('should successfully run rule where scheduled task id is different than rule id', async () => {
await retry.try(async () => {
// Sometimes the rule may already be running. Try until it isn't
// Sometimes the rule may already be running, which returns a 200. Try until it isn't
const response = await supertest
.post(`${getUrlPrefix(``)}/internal/alerting/rule/${LOADED_RULE_ID}/_run_soon`)
.set('kbn-xsrf', 'foo');
Expand All @@ -52,10 +52,13 @@ export default function createRunSoonTests({ getService }: FtrProviderContext) {
expect(response.status).to.eql(200);
objectRemover.add('default', response.body.id, 'rule', 'alerting');

const runSoonResponse = await supertest
.post(`${getUrlPrefix(``)}/internal/alerting/rule/${response.body.id}/_run_soon`)
.set('kbn-xsrf', 'foo');
expect(runSoonResponse.status).to.eql(204);
await retry.try(async () => {
// Sometimes the rule may already be running, which returns a 200. Try until it isn't
const runSoonResponse = await supertest
.post(`${getUrlPrefix(``)}/internal/alerting/rule/${response.body.id}/_run_soon`)
.set('kbn-xsrf', 'foo');
expect(runSoonResponse.status).to.eql(204);
});
});

it('should return message when task does not exist for rule', async () => {
Expand Down

0 comments on commit e486a24

Please sign in to comment.