Skip to content

Commit

Permalink
[Reporting] Fix browser diagnostic Jest test flakiness (elastic#118003)
Browse files Browse the repository at this point in the history
* mock and reduce the wait time for reading diagnoistic logs

* remove comment

* run test suite 42 times - REVERT THIS

* Revert "run test suite 42 times - REVERT THIS"

This reverts commit f9474aa.

* mock Rx.timer instead, revert previous solution

* added comment

* remove for loop

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
jloleysens and kibanamachine committed Nov 11, 2021
1 parent 2b06bb0 commit 4da06ec
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { spawn } from 'child_process';
import { createInterface } from 'readline';
import { setupServer } from 'src/core/server/test_utils';
import supertest from 'supertest';
import * as Rx from 'rxjs';
import { ReportingCore } from '../..';
import {
createMockConfigSchema,
Expand All @@ -28,8 +29,10 @@ type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
const devtoolMessage = 'DevTools listening on (ws://localhost:4000)';
const fontNotFoundMessage = 'Could not find the default font';

// FLAKY: https://github.com/elastic/kibana/issues/89369
describe.skip('POST /diagnose/browser', () => {
const wait = (ms: number): Rx.Observable<0> =>
Rx.from(new Promise<0>((resolve) => setTimeout(() => resolve(0), ms)));

describe('POST /diagnose/browser', () => {
jest.setTimeout(6000);
const reportingSymbol = Symbol('reporting');
const mockLogger = createMockLevelLogger();
Expand All @@ -53,6 +56,9 @@ describe.skip('POST /diagnose/browser', () => {
() => ({ usesUiCapabilities: () => false })
);

// Make all uses of 'Rx.timer' return an observable that completes in 50ms
jest.spyOn(Rx, 'timer').mockImplementation(() => wait(50));

core = await createMockReportingCore(
config,
createMockPluginSetup({
Expand All @@ -79,6 +85,7 @@ describe.skip('POST /diagnose/browser', () => {
});

afterEach(async () => {
jest.restoreAllMocks();
await server.stop();
});

Expand Down

0 comments on commit 4da06ec

Please sign in to comment.