Skip to content

Commit

Permalink
[Fleet] Fix flaky agentless test (elastic#197951)
Browse files Browse the repository at this point in the history
Fixes elastic#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 <[email protected]>
(cherry picked from commit a5db34b)
  • Loading branch information
criamico committed Oct 28, 2024
1 parent 0fba9b0 commit 1338cc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -529,8 +529,7 @@ describe('useSetupTechnology', () => {
packagePolicy: packagePolicyMock,
})
);

await waitForNextUpdate();
await rerender();

expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENT_BASED);

Expand All @@ -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 () => {
Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/fleet/public/mock/create_test_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 1338cc6

Please sign in to comment.