kibana/.buildkite
Christos Nasikas 1054799f9c
[Cases] Improve unit test flakiness (#212489)
## Summary

This PR attempts (I have lost count of how many there have been so far)
to stabilize the flakiness of cases tests.

## Approach

Based on our investigations, I believe a common factor that causes all
tests to time out is how we wrap the tests with the needed providers.
Instead of figuring out why they time out (which is very difficult), I
tried a different approach. I rewrote how we initialize the testing
dependencies, mocks, and providers on tests. To test my theory, I
created a VM instance in GCloud with the same configuration as the one
running in the CI, specifically the n2-standard-4 (4 vCPUs, 16 GB
Memory) machine type. I ran the tests 100 times, which took almost two
days. In 10 of the runs, a random test was timeouted. I noticed that the
machine was stressed while running the tests, and the CPU frequently
spiked to 100%, especially at the beginning of each test. Then, I
increased the timeout for all cases tests to 10 seconds and ran the
tests again 100 times. No timeouts occurred. Lastly, I created a VM
instance in GCloud with the same configuration as the one running in the
CI, specifically the n2-standard-8 (8 vCPUs, 32 GB Memory) machine type.
I ran the tests again 100 times. In 1 of the runs, a random test was
timeouted. The machine on the CI cannot handle the cases tests. I
believe the work in this PR is a step in the right direction either way,
and we will benefit from it. I also believe increasing the timeout is a
good decision as we need it based on the experiments and the research we
have done in the last months.

CPU usage on n2-standard-4


https://github.com/user-attachments/assets/36b035df-310f-4906-98ba-688d57b97c7e

CPU usage on n2-standard-8


https://github.com/user-attachments/assets/3b1b6351-d48e-41da-a413-a56e52b54b82

## RLT eslint rules
I enabled the [RLT eslint
rules](https://testing-library.com/docs/ecosystem-eslint-plugin-testing-library/)
for Cases and resolved any eslint errors. The process revealed small
bugs in the tests, which I fixed them.

## Testing utils

I removed the `appMockRender` and any usage in favor of the new
`renderWithTestingProviders` utility function and the improved
`TestProviders` component. The `renderWithTestingProviders` follows the
principals
[suggested](https://github.com/testing-library/react-testing-library/issues/780#issuecomment-689053441)
by the RLT team. Specifically:
- The `renderWithTestingProviders` is a wrapper of the `render` function
of the RTL library.
- The `renderWithTestingProviders` does not create the services or any
component inside it.
- The `renderWithTestingProviders` cannot be used in `beforeEach`
functions. It should be called separately on each test.
- The `renderWithTestingProviders` accepts props to override the default
mocks.
- The `renderWithTestingProviders` passes the `TestProviders` in the
`wrapper` argument of the RLT `render` function.
- The `TestProviders` component initializes and memoizes all services
and dependencies. It accepts props to override the default mocks.
- Mock overrides (like core services) should be created and passed to
`renderWithTestingProviders` on each test, even if it means duplication.
We favor test isolation.

### Checklist

Check the PR satisfies the following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

## Issues
<details>
<summary>List</summary>

Fixes: https://github.com/elastic/kibana/issues/207712
Fixes: https://github.com/elastic/kibana/issues/192739
Fixes: https://github.com/elastic/kibana/issues/174682
Fixes: https://github.com/elastic/kibana/issues/206366
Fixes: https://github.com/elastic/kibana/issues/207427
Fixes: https://github.com/elastic/kibana/issues/175239
Fixes: https://github.com/elastic/kibana/issues/177334
Fixes: https://github.com/elastic/kibana/issues/208443
Fixes: https://github.com/elastic/kibana/issues/187526
Fixes: https://github.com/elastic/kibana/issues/208310
Fixes: https://github.com/elastic/kibana/issues/192640
Fixes: https://github.com/elastic/kibana/issues/207077
Fixes: https://github.com/elastic/kibana/issues/197304
Fixes: https://github.com/elastic/kibana/issues/207249
Fixes: https://github.com/elastic/kibana/issues/202761
Fixes: https://github.com/elastic/kibana/issues/202115
Fixes: https://github.com/elastic/kibana/issues/193026
Fixes: https://github.com/elastic/kibana/issues/177304
Fixes: https://github.com/elastic/kibana/issues/208415
Fixes: https://github.com/elastic/kibana/issues/174661
Fixes: https://github.com/elastic/kibana/issues/201611
Fixes: https://github.com/elastic/kibana/issues/182364
Fixes: https://github.com/elastic/kibana/issues/175841
Fixes: https://github.com/elastic/kibana/issues/207907
Fixes: https://github.com/elastic/kibana/issues/171177
Fixes: https://github.com/elastic/kibana/issues/196628
Fixes: https://github.com/elastic/kibana/issues/194703
Fixes: https://github.com/elastic/kibana/issues/207241
Fixes: https://github.com/elastic/kibana/issues/206056
Fixes: https://github.com/elastic/kibana/issues/207328
Fixes: https://github.com/elastic/kibana/issues/205953
Fixes: https://github.com/elastic/kibana/issues/176524
Fixes: https://github.com/elastic/kibana/issues/176335
Fixes: https://github.com/elastic/kibana/issues/207404
Fixes: https://github.com/elastic/kibana/issues/207384
Fixes: https://github.com/elastic/kibana/issues/208380
Fixes: https://github.com/elastic/kibana/issues/207248
Fixes: https://github.com/elastic/kibana/issues/207444
Fixes: https://github.com/elastic/kibana/issues/175240
Fixes: https://github.com/elastic/kibana/issues/178001

</details>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-03-14 17:17:13 +00:00
..
hooks [Ops] Refactor env loading & fix agent-targeting rewrite (#178320) 2024-03-12 16:31:26 +01:00
pipeline-resource-definitions [CI] remove 8.15 es snapshot build schedule (#213607) 2025-03-10 10:57:54 +01:00
pipeline-utils [scout] add dynamic ci pipeline to run tests (#211797) 2025-03-11 18:15:08 +01:00
pipelines [ci] remove diskSize definition in scout_tests.yml (#214122) 2025-03-12 13:53:01 +01:00
scripts SKA: Relocate /test to /src/platform/test (#210956) 2025-03-14 16:57:23 +00:00
.mocharc.json [CI] Move kibana-buildkite-library into kibana (#134787) 2022-06-28 13:19:05 -04:00
.npmrc [CI] Move kibana-buildkite-library into kibana (#134787) 2022-06-28 13:19:05 -04:00
disabled_jest_configs.json [Index Management] Fix broken jest tests (#173029) 2023-12-18 17:21:28 +01:00
ftr_base_serverless_configs.yml [FTR] support "deployment agnostic" api-integration tests (#189853) 2024-08-07 10:34:52 -05:00
ftr_configs_manifests.json [FTR] split configs by target into multiple manifest files (#187440) 2024-07-19 15:00:53 +02:00
ftr_oblt_serverless_configs.yml [Discover] Add context awareness telemetry tests for Observability profiles (#201310) 2024-11-28 20:12:26 -04:00
ftr_oblt_stateful_configs.yml [Profiling] Migrate Profiling Cypress tests to on_merge from on_merge_unsupported_ftrs (#206727) 2025-01-21 17:09:42 +01:00
ftr_platform_stateful_configs.yml [Cases] Improve unit test flakiness (#212489) 2025-03-14 17:17:13 +00:00
ftr_search_serverless_configs.yml Balance serverless test groups 2024-11-27 17:00:05 +02:00
ftr_search_stateful_configs.yml [FTR] split configs by target into multiple manifest files (#187440) 2024-07-19 15:00:53 +02:00
ftr_security_serverless_configs.yml [Security Solution] Enable prebuilt rules customization feature flag (#212761) 2025-03-11 22:45:49 +01:00
ftr_security_stateful_configs.yml [Security Solution] Enable prebuilt rules customization feature flag (#212761) 2025-03-11 22:45:49 +01:00
package-lock.json [ci] Click to deploy cloud (#205623) 2025-01-23 10:26:03 +01:00
package.json [ci] Click to deploy cloud (#205623) 2025-01-23 10:26:03 +01:00
pull_requests.json [ci] Click to deploy cloud (#205623) 2025-01-23 10:26:03 +01:00
README.md [CI] Move kibana-buildkite-library into kibana (#134787) 2022-06-28 13:19:05 -04:00
tsconfig.json fix(NA): adds pipeline-resource-definitions/fix-location-collection.ts into a tsconfig 2024-04-04 15:16:01 +01:00
tsconfig.test.json [CI] Move kibana-buildkite-library into kibana (#134787) 2022-06-28 13:19:05 -04:00

Kibana / Buildkite

Directory Structure

  • hooks - special directory used by Buildkite agents for hooks
  • pipeline-utils - Shared TypeScript utils for use in pipeline scripts
  • pipelines - contains pipeline definitions
  • scripts/common - scripts that get sourced by other scripts to set environment variables or import shared functions
  • scripts/lifecycle - general scripts for tasks that run before or after individual steps or the entire build
  • scripts/steps - scripts that define something that will run for a step defined in a pipeline
  • scripts/* - all other scripts are building blocks that make up the tasks in pipelines. They may be run by other scripts, but should not be sourced