Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor index management client integration tests for scalability #67917

Conversation

cjcenizal
Copy link
Contributor

The biggest change I made in this PR was to extract the index templates tab tests into their own file. I think this increases scalability because we can test additional tabs by adding additional files.

I also think the general pattern we have for unit tests is to colocate them with tested code, so I updated the flatten_object tests to follow that pattern.

Another small change was to remove unused mocks.

@cjcenizal cjcenizal added chore Feature:Index Management Index and index templates UI v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v7.9.0 labels Jun 1, 2020
@cjcenizal cjcenizal requested a review from a team as a code owner June 1, 2020 23:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @cjcenizal! I think this extraction makes sense.

What do you think about taking it a step further? For example, I could see only testing the IndexTemplates tab component, rather than mounting the home component within the home_index_templates_tab.test.ts. That could also eliminate some of the setup code (for example, here and here). Similarly, I could also see having an "indices tab" test that could further extract some of the tests in home.test.ts.

This might be outside the scope of what you wanted to do here though 😄

@cjcenizal
Copy link
Contributor Author

cjcenizal commented Jun 2, 2020

@alisonelizabeth Great suggestion! Can you take another look? I extracted out these tests into their own files. Note that I couldn't consume the TemplateList component because we depend upon react router to tell us which template to open in the detail panel, and the Home component contains the enclosing Route component. Maybe in a future iteration we can solve this. I left a code comment along these lines.

I also decided to extract and colocate the helpers with the tests that consume them. This significantly deflated the shared helpers directory. I think this makes it easier to understand which tests use which helpers. Let me know what you think.

@cjcenizal
Copy link
Contributor Author

Also, I was able to reproduce a flaky test at one point. Of course, it was flaky so it happened once and I wasn't able to reproduce it again.

image

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I left a few comments in the code for info. Thanks for doing this 👍 !

import {
registerTestBed,
TestBed,
TestBedConfig,
findTestSubject,
nextTick,
} from '../../../../../test_utils';
// NOTE: We have to use the Home component instead of the TemplateList component because we depend
// upon react router to provide the name of the template to load in the detail panel.
Copy link
Contributor

@sebelga sebelga Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something around those lines should work

const CompToTest = () => {
  return (
    <Switch>
      <Route exact path="templates/:templateName*" component={TemplateList} />
     </Switch>
  );
};

const testBedConfig: TestBedConfig = {
  memoryRouter: {
    initialEntries: ["templates"],
    componentRoutePath: "templates", // or maybe an empty ""?
  },
  doMountAsync: true,
};

const setup = registerTestBed(WithAppDependencies(CompToTest), testBedConfig);

Copy link
Contributor Author

@cjcenizal cjcenizal Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Seb! I took a stab at this and every test started failing. I'm going to merge this in its current state to enable us to add tests for data streams etc. using this new organization, with the expectation that we'll address your comments separately.


actions.selectHomeTab('templatesTab');

await act(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info: This block is exactly what we want to remove everywhere. It creates latency in the tests and could be the cause of flakiness.

It should be written

act(() => {
  // this is causing states updates. There can only be **one** in each act() call
  // It should be synchronous if possible.
  // Sometimes hook update require async, so if there is an error in console --> use async act()
  actions.selectHomeTab('templatesTab');
});

// If I need a second action straightaway, we use another act()
act(() => {
  actions.doSomethingElse();
});

// And we only need to call update() once after all actions
component.update();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, we could wrap the act() inside our helpers' actions and keep the test file cleaner.

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest changes LGTM. Thanks @cjcenizal!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@cjcenizal cjcenizal changed the title Refactor index management client integration tests Refactor index management client integration tests for scalability Jun 3, 2020
@cjcenizal cjcenizal merged commit 573409b into elastic:master Jun 3, 2020
@cjcenizal cjcenizal deleted the refactor/index-management-client-integration-tests branch June 3, 2020 23:49
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 4, 2020
…ms-column

* 'master' of github.com:elastic/kibana: (63 commits)
  remove scripts. prettire update has been done (elastic#68130)
  Closes elastic#68055 by detecting the local Kibana version and using that as (elastic#68198)
  [apm] docs: add deployment annotation example (elastic#67408)
  [ML] Extend population preview chart to show actual and typical value (elastic#67569)
  Refactor index management client integration tests for scalability (elastic#67917)
  Add generator function that creates multiple alerts (elastic#67713)
  chore(NA): remove config arg from os packages (elastic#67871)
  [Reporting] Move code out of Legacy (elastic#67904)
  [Metrics UI] Add overrides to Snapshot API to support alert previews (elastic#68125)
  [Security] [Cases] Manage timeline UI API (elastic#67719)
  [ENDPOINT][INGEST]Task/endpoint ingest update (elastic#67234)
  Fix code coverage for jest, upload merged reports (elastic#68149)
  Update documentation/examples of deprecated namespaceAgnostic field (elastic#68039)
  [DOCS] Updates Canvas docs with new menus (elastic#66061)
  chore(NA): avoids imports of server or public code into common (elastic#67231)
  [SIEM] Fix GetOneTimeline graphql type (elastic#68137)
  skip flaky suite (elastic#67838)
  [Uptime] Add loading message for monitor list no items (elastic#67378)
  [Ingest Manager] Update indexing strategy docs to use dataset.* (elastic#68068)
  [Ingest Manager] Fix datasource validation for streams without vars (elastic#67950)
  ...

# Conflicts:
#	x-pack/plugins/index_management/__jest__/client_integration/helpers/index.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home.test.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jun 4, 2020
* master: (26 commits)
  [Console]remove completion for type for filter queries and aggs (elastic#68103)
  [ML] Transforms: Filter aggregation support (elastic#67591)
  [ES UI Shared] Monaco XJSON (elastic#67485)
  [Index Management] Add data streams functionality to indices tab (elastic#67940)
  [Discover] Fix renaming of saved search not displayed in breadcrumb (elastic#67577)
  [SECURITY] Rename siem plugin to security_solution (elastic#67902)
  [Uptime] Fix Telemetry Api flaky test (elastic#67358)
  [Data plugin] Add configuration property to enable / disable autocomplete (elastic#67847)
  remove scripts. prettire update has been done (elastic#68130)
  Closes elastic#68055 by detecting the local Kibana version and using that as (elastic#68198)
  [apm] docs: add deployment annotation example (elastic#67408)
  [ML] Extend population preview chart to show actual and typical value (elastic#67569)
  Refactor index management client integration tests for scalability (elastic#67917)
  Add generator function that creates multiple alerts (elastic#67713)
  chore(NA): remove config arg from os packages (elastic#67871)
  [Reporting] Move code out of Legacy (elastic#67904)
  [Metrics UI] Add overrides to Snapshot API to support alert previews (elastic#68125)
  [Security] [Cases] Manage timeline UI API (elastic#67719)
  [ENDPOINT][INGEST]Task/endpoint ingest update (elastic#67234)
  Fix code coverage for jest, upload merged reports (elastic#68149)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:Index Management Index and index templates UI release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants