Skip to content

Commit

Permalink
[8.x] [Fleet] Fix flaky agentless test (#197951) (#198053)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Fix flaky agentless test
(#197951)](#197951)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-28T16:57:10Z","message":"[Fleet]
Fix flaky agentless test (#197951)\n\nFixes
https://github.com/elastic/kibana/issues/189038\r\n\r\n##
Summary\r\n\r\nAttempt to fix [this flaky
test\r\n](https://buildkite.com/elastic/kibana-on-merge/builds/53472#0192c57d-51ca-4b9b-a934-dc13b0b9b7ca)\r\nfailing
with\r\n```\r\n\r\nTimed out in waitForNextUpdate after
1000ms.\r\n--\r\n  |  \r\n  | at waitForNextUpdate
(node_modules/@testing-library/react-hooks/lib/core/asyncUtils.js:96:13)\r\n\r\n```\r\nI'm
adding a longer timeout hoping to resolve this issue. There is no\r\nway
to run jest tests with flaky test runner so I'm not sure how
to\r\nverify that the flakiness is really
gone.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"a5db34b2f58888913ae1bb433803b9999df7a739","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[Fleet]
Fix flaky agentless
test","number":197951,"url":"https://github.com/elastic/kibana/pull/197951","mergeCommit":{"message":"[Fleet]
Fix flaky agentless test (#197951)\n\nFixes
https://github.com/elastic/kibana/issues/189038\r\n\r\n##
Summary\r\n\r\nAttempt to fix [this flaky
test\r\n](https://buildkite.com/elastic/kibana-on-merge/builds/53472#0192c57d-51ca-4b9b-a934-dc13b0b9b7ca)\r\nfailing
with\r\n```\r\n\r\nTimed out in waitForNextUpdate after
1000ms.\r\n--\r\n  |  \r\n  | at waitForNextUpdate
(node_modules/@testing-library/react-hooks/lib/core/asyncUtils.js:96:13)\r\n\r\n```\r\nI'm
adding a longer timeout hoping to resolve this issue. There is no\r\nway
to run jest tests with flaky test runner so I'm not sure how
to\r\nverify that the flakiness is really
gone.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"a5db34b2f58888913ae1bb433803b9999df7a739"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197951","number":197951,"mergeCommit":{"message":"[Fleet]
Fix flaky agentless test (#197951)\n\nFixes
https://github.com/elastic/kibana/issues/189038\r\n\r\n##
Summary\r\n\r\nAttempt to fix [this flaky
test\r\n](https://buildkite.com/elastic/kibana-on-merge/builds/53472#0192c57d-51ca-4b9b-a934-dc13b0b9b7ca)\r\nfailing
with\r\n```\r\n\r\nTimed out in waitForNextUpdate after
1000ms.\r\n--\r\n  |  \r\n  | at waitForNextUpdate
(node_modules/@testing-library/react-hooks/lib/core/asyncUtils.js:96:13)\r\n\r\n```\r\nI'm
adding a longer timeout hoping to resolve this issue. There is no\r\nway
to run jest tests with flaky test runner so I'm not sure how
to\r\nverify that the flakiness is really
gone.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"a5db34b2f58888913ae1bb433803b9999df7a739"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <[email protected]>
  • Loading branch information
kibanamachine and criamico authored Oct 28, 2024
1 parent 53dacb5 commit 92f6a18
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 92f6a18

Please sign in to comment.