Skip to content

Commit

Permalink
Adding functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Apr 1, 2022
1 parent 1cb70d4 commit afedf2d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,23 +675,32 @@ export function defineAlertTypes(
throw new Error('this alert is intended to fail');
},
};
const longRunningAlertType: RuleType<{}, {}, {}, {}, {}, 'default'> = {
id: 'test.longRunning',
name: 'Test: Long Running',
actionGroups: [
{
id: 'default',
name: 'Default',
function getLongRunningRuleType() {
const paramsSchema = schema.object({
delay: schema.maybe(schema.number({ defaultValue: 5000 })),
});
type ParamsType = TypeOf<typeof paramsSchema>;

const result: RuleType<ParamsType, {}, {}, {}, {}, 'default'> = {
id: 'test.longRunning',
name: 'Test: Long Running',
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
producer: 'alertsFixture',
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
isExportable: true,
async executor(ruleExecutorOptions) {
const { params } = ruleExecutorOptions;
await new Promise((resolve) => setTimeout(resolve, params.delay ?? 5000));
},
],
producer: 'alertsFixture',
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
isExportable: true,
async executor() {
await new Promise((resolve) => setTimeout(resolve, 5000));
},
};
};
return result;
}
const exampleAlwaysFiringAlertType: RuleType<{}, {}, {}, {}, {}, 'small' | 'medium' | 'large'> = {
id: 'example.always-firing',
name: 'Always firing',
Expand Down Expand Up @@ -769,7 +778,7 @@ export function defineAlertTypes(
alerting.registerType(onlyStateVariablesAlertType);
alerting.registerType(getPatternFiringAlertType());
alerting.registerType(throwAlertType);
alerting.registerType(longRunningAlertType);
alerting.registerType(getLongRunningRuleType());
alerting.registerType(goldNoopAlertType);
alerting.registerType(exampleAlwaysFiringAlertType);
alerting.registerType(multipleSearchesRuleType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ export default function createGetExecutionLogTests({ getService }: FtrProviderCo
expect(response.body.errors).to.eql([]);
});

it('gets execution log for rule that is currently running', async () => {
const { body: createdRule } = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.send(getTestRuleData({ rule_type_id: 'test.longRunning', params: { delay: 120000 } }))
.expect(200);
objectRemover.add(Spaces.space1.id, createdRule.id, 'rule', 'alerting');

// wait for execute-start event that signals rule has started running
await waitForEvents(createdRule.id, 'alerting', new Map([['execute-start', { gte: 1 }]]));

const response = await supertest.get(
`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${
createdRule.id
}/_execution_log?date_start=${dateStart}`
);

expect(response.status).to.eql(200);

// since these events should have been excluded from the agg, should return empty
expect(response.body.total).to.eql(0);
expect(response.body.data).to.eql([]);
expect(response.body.totalErrors).to.eql(0);
expect(response.body.errors).to.eql([]);
});

it('gets execution log for rule that performs ES searches', async () => {
const { body: createdRule } = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`)
Expand Down

0 comments on commit afedf2d

Please sign in to comment.