From 1338cc61ad874864601b5149e49ca0610e3e8a50 Mon Sep 17 00:00:00 2001 From: Cristina Amico Date: Mon, 28 Oct 2024 17:57:10 +0100 Subject: [PATCH] [Fleet] Fix flaky agentless test (#197951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/elastic/kibana/issues/189038 ## Summary Attempt to fix [this flaky test ](https://buildkite.com/elastic/kibana-on-merge/builds/53472#0192c57d-51ca-4b9b-a934-dc13b0b9b7ca) failing with ``` Timed out in waitForNextUpdate after 1000ms. --   |     | at waitForNextUpdate (node_modules/@testing-library/react-hooks/lib/core/asyncUtils.js:96:13) ``` I'm adding a longer timeout hoping to resolve this issue. There is no way to run jest tests with flaky test runner so I'm not sure how to verify that the flakiness is really gone. --------- Co-authored-by: Elastic Machine (cherry picked from commit a5db34b2f58888913ae1bb433803b9999df7a739) --- .../hooks/setup_technology.test.ts | 21 +++++++------------ .../public/mock/create_test_renderer.tsx | 12 ++++++++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts index 38663d88e5b23..ebdc578a04752 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts @@ -520,7 +520,7 @@ describe('useSetupTechnology', () => { }); it('should revert the agent policy name to the original value when switching from agentless back to agent-based', async () => { - const { result, waitForNextUpdate } = renderHook(() => + const { result, rerender } = renderHook(() => useSetupTechnology({ setNewAgentPolicy, newAgentPolicy: newAgentPolicyMock, @@ -529,8 +529,7 @@ describe('useSetupTechnology', () => { packagePolicy: packagePolicyMock, }) ); - - await waitForNextUpdate(); + await rerender(); expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENT_BASED); @@ -539,21 +538,17 @@ describe('useSetupTechnology', () => { }); expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS); - - waitFor(() => { - expect(setNewAgentPolicy).toHaveBeenCalledWith({ - name: 'Agentless policy for endpoint-1', - supports_agentless: true, - inactivity_timeout: 3600, - }); + expect(setNewAgentPolicy).toHaveBeenCalledWith({ + id: 'agentless-policy-id', }); act(() => { result.current.handleSetupTechnologyChange(SetupTechnology.AGENT_BASED); }); - - expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENT_BASED); - expect(setNewAgentPolicy).toHaveBeenCalledWith(newAgentPolicyMock); + await waitFor(() => { + expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENT_BASED); + expect(setNewAgentPolicy).toHaveBeenCalledWith(newAgentPolicyMock); + }); }); it('should have global_data_tags with the integration team when updating the agentless policy', async () => { diff --git a/x-pack/plugins/fleet/public/mock/create_test_renderer.tsx b/x-pack/plugins/fleet/public/mock/create_test_renderer.tsx index 3a69f5fdc52e3..66155cee7bb35 100644 --- a/x-pack/plugins/fleet/public/mock/create_test_renderer.tsx +++ b/x-pack/plugins/fleet/public/mock/create_test_renderer.tsx @@ -59,7 +59,17 @@ export interface TestRenderer { setHeaderActionMenu: Function; } -const queryClient = new QueryClient(); +// disable retries to avoid test flakiness +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: false, + }, + mutations: { + retry: false, + }, + }, +}); export const createFleetTestRendererMock = (): TestRenderer => { const basePath = '/mock';