Skip to content

Commit

Permalink
[EventLog] Use performance.now() rather than Date.now() to calculate …
Browse files Browse the repository at this point in the history
…elapsed time in tests (#158721)

Resolves: #156061

Since all the failed CI results show actual elapsed time as `19` rather
than `20` (expected), the issue seems like an inaccurate time
calculation caused by `Date.now()` method.

Replacing `Date.now()` with the more precise `performance.now()` method
may solve the problem.
  • Loading branch information
ersin-erdal authored Jun 1, 2023
1 parent 109e67b commit 72fa065
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions x-pack/plugins/event_log/server/es/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ describe('parseIndexAliases', () => {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/156061
describe.skip('retries', () => {
describe('retries', () => {
let esContext = contextMock.create();
// set up context APIs to return defaults indicating already created
beforeEach(() => {
Expand All @@ -472,9 +471,9 @@ describe.skip('retries', () => {
test('createIlmPolicyIfNotExists with 1 retry', async () => {
esContext.esAdapter.doesIlmPolicyExist.mockRejectedValueOnce(new Error('retry 1'));

const timeStart = Date.now();
const timeStart = performance.now();
await initializeEs(esContext);
const timeElapsed = Date.now() - timeStart;
const timeElapsed = performance.now() - timeStart;

expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY);

Expand All @@ -492,9 +491,9 @@ describe.skip('retries', () => {
esContext.esAdapter.doesIndexTemplateExist.mockRejectedValueOnce(new Error('retry 2a'));
esContext.esAdapter.doesIndexTemplateExist.mockRejectedValueOnce(new Error('retry 2b'));

const timeStart = Date.now();
const timeStart = performance.now();
await initializeEs(esContext);
const timeElapsed = Date.now() - timeStart;
const timeElapsed = performance.now() - timeStart;

expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY * (1 + 2));

Expand All @@ -518,9 +517,9 @@ describe.skip('retries', () => {
// make sure it only tries 5 times - this one should not be reported
esContext.esAdapter.doesAliasExist.mockRejectedValueOnce(new Error('retry 5f'));

const timeStart = Date.now();
const timeStart = performance.now();
await initializeEs(esContext);
const timeElapsed = Date.now() - timeStart;
const timeElapsed = performance.now() - timeStart;

expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY * (1 + 2 + 4 + 8));

Expand Down

0 comments on commit 72fa065

Please sign in to comment.