Skip to content

Commit

Permalink
[ResponseOps][Alerting] Fixing flaky tests in task_management.ts (#14…
Browse files Browse the repository at this point in the history
…1441)

* Fixing flaky test

* Updating tests

* Fixing tests again

* Update x-pack/test/plugin_api_integration/test_suites/task_manager/task_management.ts

Co-authored-by: Ying Mao <[email protected]>

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Updating for pr comments

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Missing lint

* Updating check

* Adding type

* Remove runAt

Co-authored-by: Ying Mao <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2022
1 parent 3154b2a commit 85300bb
Showing 1 changed file with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const testHistoryIndex = '.kibana_task_manager_test_result';

// Failing: See https://github.com/elastic/kibana/issues/141002
describe.skip('scheduling and running tasks', () => {
describe('scheduling and running tasks', () => {
beforeEach(async () => {
// clean up before each test
return await supertest.delete('/api/sample_tasks').set('kbn-xsrf', 'xxx').expect(200);
Expand Down Expand Up @@ -646,77 +645,70 @@ export default function ({ getService }: FtrProviderContext) {
const historyItem = random(1, 100);
const scheduledTask = await scheduleTask({
taskType: 'sampleTask',
schedule: { interval: '30m' },
schedule: { interval: '1h' },
params: { historyItem },
});

await retry.try(async () => {
expect((await historyDocs()).length).to.eql(1);
const tasks = (await currentTasks()).docs;
const task = await currentTask(scheduledTask.id);

expect(getTaskById(tasks, scheduledTask.id).enabled).to.eql(true);
expect(task.enabled).to.eql(true);
});

// disable the task
await bulkDisable([scheduledTask.id]);

await retry.try(async () => {
const tasks = (await currentTasks()).docs;

expect(getTaskById(tasks, scheduledTask.id).enabled).to.eql(false);
const task = await currentTask(scheduledTask.id);
expect(task.enabled).to.eql(false);
});

// re-enable the task
await bulkEnable([scheduledTask.id], true);

await retry.try(async () => {
const tasks = (await currentTasks()).docs;

expect(getTaskById(tasks, scheduledTask.id).enabled).to.eql(true);
const task = await currentTask(scheduledTask.id);

// should get a new document even tho original schedule interval was 30m
expect((await historyDocs()).length).to.eql(2);
expect(task.enabled).to.eql(true);
expect(Date.parse(task.scheduledAt)).to.be.greaterThan(
Date.parse(scheduledTask.scheduledAt)
);
expect(Date.parse(task.runAt)).to.be.greaterThan(Date.parse(scheduledTask.runAt));
});
});

it('should disable and reenable task and not run it when runSoon = false', async () => {
const historyItem = random(1, 100);
const scheduledTask = await scheduleTask({
taskType: 'sampleTask',
schedule: { interval: '30m' },
schedule: { interval: '1h' },
params: { historyItem },
});

await retry.try(async () => {
expect((await historyDocs()).length).to.eql(1);
const tasks = (await currentTasks()).docs;

expect(getTaskById(tasks, scheduledTask.id).enabled).to.eql(true);
const task = await currentTask(scheduledTask.id);
expect(task.enabled).to.eql(true);
});

// disable the task
await bulkDisable([scheduledTask.id]);

await retry.try(async () => {
const tasks = (await currentTasks()).docs;

expect(getTaskById(tasks, scheduledTask.id).enabled).to.eql(false);
const task = await currentTask(scheduledTask.id);
expect(task.enabled).to.eql(false);
});

// re-enable the task
await bulkEnable([scheduledTask.id], false);

await retry.try(async () => {
const tasks = (await currentTasks()).docs;

const task = getTaskById(tasks, scheduledTask.id);
const task = await currentTask(scheduledTask.id);

expect(task.enabled).to.eql(true);

// task runAt should be set in the future by greater than 20 minutes
// this assumes it takes less than 10 minutes to disable and renable the task
// since the schedule interval is 30 minutes
expect(Date.parse(task.runAt) - Date.now()).to.be.greaterThan(10 * 60 * 1000);
expect(Date.parse(task.scheduledAt)).to.eql(Date.parse(scheduledTask.scheduledAt));
});
});

Expand Down

0 comments on commit 85300bb

Please sign in to comment.