mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Fixing flaky test (#139662)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
26a503daa7
commit
8d888be4d3
1 changed files with 12 additions and 8 deletions
|
@ -59,31 +59,35 @@ describe('TaskRunnerTimer', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// FLAKY: https://github.com/elastic/kibana/issues/139634
|
||||
describe.skip('runWithTimer', () => {
|
||||
describe('runWithTimer', () => {
|
||||
test('should calculate time it takes to run callback function for a given timer span', async () => {
|
||||
const delay = 2000;
|
||||
const result = await timer.runWithTimer(TaskRunnerTimerSpan.ProcessAlerts, async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
return 'done!';
|
||||
});
|
||||
|
||||
expect(result).toEqual('done!');
|
||||
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeGreaterThan(2000);
|
||||
// We would expect this to be greater than the delay value but add a fudge factor to avoid flakiness
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeGreaterThanOrEqual(delay - 5);
|
||||
});
|
||||
|
||||
test('should log warning and overwrite duration if called twice for same span', async () => {
|
||||
const prevDelay = 2000;
|
||||
const delay = 1000;
|
||||
await timer.runWithTimer(TaskRunnerTimerSpan.ProcessAlerts, async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
await new Promise((resolve) => setTimeout(resolve, prevDelay));
|
||||
return 'done!';
|
||||
});
|
||||
await timer.runWithTimer(TaskRunnerTimerSpan.ProcessAlerts, async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
return 'done!';
|
||||
});
|
||||
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeGreaterThan(1000);
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeLessThan(2000);
|
||||
// We would expect this to be greater than the delay value but add a fudge factor to avoid flakiness
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeGreaterThanOrEqual(delay - 5);
|
||||
expect(timer.toJson().process_alerts_duration_ms).toBeLessThan(prevDelay);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue