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]>
  • Loading branch information
2 people authored and tiansivive committed Oct 29, 2024
1 parent f5aa3e2 commit d2f700f
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 @@ -592,7 +592,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 @@ -601,8 +601,7 @@ describe('useSetupTechnology', () => {
packagePolicy: packagePolicyMock,
})
);

await waitForNextUpdate();
await rerender();

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

Expand All @@ -611,21 +610,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 d2f700f

Please sign in to comment.