Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Response Ops][Test] Debugging Flaky Tests #192892

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rollback some changes and logs
  • Loading branch information
jcger committed Sep 18, 2024
commit e8727c0d660d3de3d68988869ae4c98b122ed016
18 changes: 4 additions & 14 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type { PropsWithChildren } from 'react';
import React, { useMemo } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { act, render as reactRender, waitFor } from '@testing-library/react';
import { render as reactRender, waitFor } from '@testing-library/react';
import type { RenderOptions, RenderResult } from '@testing-library/react';
import type { ILicense } from '@kbn/licensing-plugin/public';
import type { ScopedFilesClient } from '@kbn/files-plugin/public';
Expand Down Expand Up @@ -80,7 +80,6 @@ const TestProvidersComponent: React.FC<TestProviderProps> = ({
defaultOptions: {
queries: {
retry: false,
staleTime: 0,
},
},
logger: {
Expand Down Expand Up @@ -145,7 +144,6 @@ export const createAppMockRenderer = ({
defaultOptions: {
queries: {
retry: false,
staleTime: 0,
},
},
logger: {
Expand Down Expand Up @@ -183,18 +181,10 @@ export const createAppMockRenderer = ({
AppWrapper.displayName = 'AppWrapper';

const render: UiRender = (ui, options) => {
let result: RenderResult | undefined;
// ensures that all the effects and state updates are processed before the function completes
act(() => {
result = reactRender(ui, {
wrapper: AppWrapper,
...options,
});
return reactRender(ui, {
wrapper: AppWrapper,
...options,
});
if (!result) {
throw new Error('Render result is undefined');
}
return result;
};

const clearQueryCache = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,35 +715,21 @@ describe('AllCasesListGeneric', () => {
[CaseSeverity.HIGH],
[CaseSeverity.CRITICAL],
])('Bulk update severity: %s', async (severity) => {
const t0 = performance.now();
appMockRenderer.render(<AllCasesList />);
const t1 = performance.now();
console.log(`1.1 Call to render took ${t1 - t0} milliseconds`);

expect(await screen.findByTestId('cases-table')).toBeInTheDocument();

const t2 = performance.now();
console.log(`1.2 Call to click took ${t2 - t1} milliseconds`);
await userEvent.click(await screen.findByTestId('checkboxSelectAll'));
const t3 = performance.now();
console.log(`1.3 Call to click took ${t3 - t2} milliseconds`);
await userEvent.click(await screen.findByText('Bulk actions'));
const t4 = performance.now();
console.log(`1.4 Call to click took ${t4 - t3} milliseconds`);
await userEvent.click(await screen.findByTestId('case-bulk-action-severity'), {
pointerEventsCheck: 0,
});
const t5 = performance.now();
console.log(`1.5 Call to click took ${t5 - t4} milliseconds`);

expect(
await screen.findByTestId(`cases-bulk-action-severity-${severity}`)
).toBeInTheDocument();
const t6 = performance.now();
console.log(`1.6 Call to click took ${t6 - t5} milliseconds`);

await userEvent.click(await screen.findByTestId(`cases-bulk-action-severity-${severity}`));
const t7 = performance.now();
console.log(`1.7 Call to click took ${t7 - t6} milliseconds`);
let t8;
await waitFor(() => {
expect(updateCasesSpy).toBeCalledWith({
cases: useGetCasesMockState.data.cases.map(({ id, version }) => ({
Expand All @@ -752,45 +738,24 @@ describe('AllCasesListGeneric', () => {
severity,
})),
});
t8 = performance.now();
console.log(`1.8 Call to click took ${t8 - t7} milliseconds`);
});
});

// https://github.com/elastic/kibana/issues/148486
it('Bulk delete', async () => {
const t0 = performance.now();
appMockRenderer.render(<AllCasesList />);

const t1 = performance.now();
console.log(`1.9 Call to render took ${t1 - t0} milliseconds`);
expect(await screen.findByTestId('cases-table')).toBeInTheDocument();

const t2 = performance.now();
console.log(`1.10 Call to click took ${t2 - t1} milliseconds`);
await userEvent.click(await screen.findByTestId('checkboxSelectAll'));

const t3 = performance.now();
console.log(`1.11 Call to click took ${t3 - t2} milliseconds`);
await userEvent.click(await screen.findByText('Bulk actions'));

const t4 = performance.now();
console.log(`1.12 Call to click took ${t4 - t3} milliseconds`);
await userEvent.click(await screen.findByTestId('cases-bulk-action-delete'), {
pointerEventsCheck: 0,
});

const t5 = performance.now();
console.log(`1.13 Call to click took ${t5 - t4} milliseconds`);
expect(await screen.findByTestId('confirm-delete-case-modal')).toBeInTheDocument();

const t6 = performance.now();
console.log(`1.14 Call to click took ${t6 - t5} milliseconds`);
await userEvent.click(await screen.findByTestId('confirmModalConfirmButton'));

const t7 = performance.now();
console.log(`1.15 Call to click took ${t7 - t6} milliseconds`);
let t8;
await waitFor(() => {
expect(deleteCasesSpy).toHaveBeenCalledWith({
caseIds: [
Expand All @@ -804,8 +769,6 @@ describe('AllCasesListGeneric', () => {
'case-with-registered-attachment',
],
});
t8 = performance.now();
console.log(`1.16 Call to click took ${t8 - t7} milliseconds`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ describe('multi select filter', () => {
onChange,
isLoading: false,
};
const t0 = performance.now();
render(<MultiSelectFilter {...props} />);
const t1 = performance.now();
console.log(`2.1 Call to render took ${t1 - t0} milliseconds.`);

await userEvent.click(await screen.findByTestId('options-filter-popover-button-tags'));
const t2 = performance.now();
console.log(`2.2 Call to click took ${t2 - t1} milliseconds.`);
await waitForEuiPopoverOpen();

expect(await screen.findByText('4 options')).toBeInTheDocument();
Expand Down