Skip to content

Functional test setup with kbn-test package#18568

Merged
rhoboat merged 16 commits intoelastic:masterfrom
rhoboat:improve-integ-test-xpack
May 9, 2018
Merged

Functional test setup with kbn-test package#18568
rhoboat merged 16 commits intoelastic:masterfrom
rhoboat:improve-integ-test-xpack

Conversation

@rhoboat
Copy link
Copy Markdown

@rhoboat rhoboat commented Apr 25, 2018

Meta Issue: #12699

This PR improves functional test setup in Kibana and plugins. The idea is to group test files that need to run, along with the specific Elasticsearch server and Kibana server they need to run against. All of this information is now in a single config file. For each config file, we can start up servers, run tests, and tear them down. This means we can pass in multiple config files to do several iterations of this in one go.

Overview

Explanation:
Look at the READMEs (here and here).

Files:
Code that originally existed in x-pack-kibana/dev-tools/functional_tests has been migrated to Kibana, just used as a starting point for how we can run functional tests for both Kibana and X-Pack Kibana. Many of the files are the same in the new packages/kbn-test/src/functional_tests/lib.

To run

  • node scripts/functional_tests
    • By default, it runs tests using --config test/functional/config.js --config test/api_integration/config.js
    • Starts Elasticsearch and Kibana,
    • runs functional tests using test/functional/config.js
    • shuts down Elasticsearch and Kibana,
    • repeats the above with test/api_integration/config.js.

  • node scripts/functional_tests_server [--config test/functional/config.js]
    • Starts Elasticsearch and Kibana
    • Allows you to run tests from another process vianode scripts/functional_test_runner

Later PRs:

  • Kibana CI Jenkins should run node scripts/functional_tests [Functional Tests] Use @kbn/test on Kibana CI #18593
  • Improve kibanaServerArgs to be deduped and made into a small service
  • Replace functional_test_runner with functional_tests and functional_tests_server (or rename back to *_runner)

X-Pack

For x-pack, all functional, api, and saml api integration tests are run via methods exposed from Kibana.

To run

Change directory into x-pack first.

  • node scripts/functional_tests [--config test/functional/config.js --config test/api_integration/config.js --config test/saml_api_integration/config.js]
    • Starts Elasticsearch and Kibana,
    • runs functional tests using test/functional/config.js
    • shuts down Elasticsearch and Kibana,
    • repeats the above with test/api_integration/config.js, and test/saml_api_integration/config.js.

  • node scripts/functional_tests_server [--config test/functional/config.js]
    • Starts Elasticsearch and Kibana
    • Allows you to run tests from another process vianode scripts/functional_test_runner

  • Ensure --bail option still passed to ftr (don't use commander)
  • Elasticsearch to run from source in CI and snapshots locally

@rhoboat rhoboat added the Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// label Apr 25, 2018
@rhoboat rhoboat self-assigned this Apr 25, 2018
@rhoboat rhoboat requested review from azasypkin and spalger April 25, 2018 16:08
@rhoboat rhoboat added the review label Apr 25, 2018
@elasticmachine

This comment has been minimized.

@rhoboat
Copy link
Copy Markdown
Author

rhoboat commented Apr 25, 2018

Tests themselves are passing but the x-pack job failed because of

info  [o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
16:50:42        │       org.elasticsearch.bootstrap.StartupException: BindHttpException[Failed to bind to [9240]]; nested: BindException[Address already in use];

looking into this.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@rhoboat rhoboat requested a review from tylersmalley April 27, 2018 00:30
@elasticmachine

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

I like how it looks, we can handle papercuts in the follow-ups, so LGTM for non-x-pack part.

I'm still keeping review request for x-pack portion: readme is outdated and I couldn't run saml api integration tests (destructuring of xPackAPITestsConfig.get('elasticsearchServerArgs') that isn't defined and permission error when ES tries to load idp_metadata.xml), likely it's still in progress.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: we agreed to handle or at least re-consider this in the follow-up, so just a reminder here: having such default configPaths looks weird to me, but if it's fine for everyone else then we should at least mention this in README.md (same for runServers).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

as a result of moving things to cli, this was resolved and config paths are no longer referenced here. take another look?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: is there any reason why you don't use the latest available versions of deps? And IIRC we're trying to use "caret" versions whenever possible.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My reasoning was to use the same versions that are currently being used, without upgrading dependencies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does it matter what versions are currently used in Kibana if we introduce isolated (once we get rid of FTR dependency), test-only and brand new package with its own dependencies and have a chance to not rely on something that's outdated (both dependencies themselves and the way we define them in package.json since we commit yarn.lock)?

Just to be clear, it's not a big deal at all and we can discuss it after this PR is merged, I'm just trying to find common ground on this matter and not to raise this question again :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: I believe we shouldn't process both "normal" arguments (configPaths) and argv in the same function, there should be a dedicated function/cli that parses command line arguments into string[] and passes it to runTests. Having said that, I'm totally fine if we discuss it in the follow-up. (same for runServers)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Take another look? I made some cli functions using only getopts. Commander would be overkill at the moment because we also need special args to be passed to functional_test_runner. I think this should be resolved in a followup.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional nit: what if we:

  • remove await in front of resolve since it's sync function
  • mark configPath as const and not reuse it for both "resolved" and "non-resolved" path versions
  • limit scope of try/catch only to piece of code we expect errors to come from
for (const configPath of configs) {
  try {
    await runWithConfig(resolve(KIBANA_ROOT, configPath), runEs, runKbn);
  } catch (err) {
    fatalErrorHandler(err);
  }
}

But since runWithConfig already wraps its content into the same try/catch we don't need to duplicate error handling in this function and it feels like we can just inline content of runWithConfig here.

Changes are arguable, hence optional :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: what if we use options: { runEs = runElasticseach, runKbn = runKibanaServer }? With this we'll be able to only override how we run Kibana if we want to. Or you think it's not a valid use case? (same for runServers)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's a valid use case. Let's do that!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional nit: hmm, maybe let's just move esTestConfig.getUrlParts() to a variable (it's called 4 times in this function)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

or rather, use the existing servers.elasticsearch definition in this file. ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: this file isn't needed anymore, right (:tada:)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I thought I deleted it!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, it is deleted from x-pack but not from kibana.

x-pack/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: should we start sentence for every list item from the capital letter?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed-- made them all lowercase.

x-pack/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: no more x-pack-elasticsearch (and x-pack-kibana below), right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay, replacing with X-Pack

x-pack/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: it seems there is no functional_tests_single.

Copy link
Copy Markdown
Member

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

Good direction so far. Added comments inline which should allow you to entirely get rid of runEsWithXpack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be replaced with using kbn/es, and doing so the following files can be removed:

  • packages/kbn-test/src/functional_tests/lib/find_most_recently_changed.js
  • packages/kbn-test/src/functional_tests/lib/tarball.js
  • x-pack/dev-tools/functional_tests/lib/tarball.js
  • x-pack/dev-tools/functional_tests/lib/find_most_recently_changed.js

And some paths in packages/kbn-test/src/functional_tests/lib/paths.js and x-pack/dev-tools/functional_tests/lib/paths.js can also be removed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added comments inline which should allow you to entirely get rid of runEsWithXpack.

This should be replaced with using kbn/es,

So, you're saying we get rid of runElasticsearch and runEsWithXpack, both?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

^ Nevermind, yes, that makes sense. Both would go away, or just be simple methods that use kbn/es

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since running with or without x-pack is an option presented to kbn/es with license. We can probably get rid of this altogether and add as part of the configuration.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The SAML tests need their own config since they require specific ES/Kibana configuration, correct?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, the idea was to move all that SAML-specific logic from the start/run methods and into config instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changing this to an object would allow us to directly pass options to kbn/es installSnapshot/installSource.

Thinking something shaped like this:

{
    license:  'basic',
    password: 'changeme',
    esArgs: []
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Great, that's a good plan. But then they have a different appearance than the kibanaServerArgs. I guess that doesn't look too bad.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe the name should be something else, since esArgs: [] within is now the array.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@tylersmalley Your thoughts on the changes here? Did some work last Thursday to use kbn/es here, but still using proc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

(I named this myClusterStart just to try this out. Name needs to be better)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@tylersmalley How does this work today? Originally we had this

    fs.createReadStream(
      resolve(XPACK_KIBANA_ROOT, 'test/saml_api_integration/fixtures/idp_metadata.xml')
    ).pipe(
      fs.createWriteStream(resolve(esExtractPath, 'config', 'idp_metadata.xml'))
    );

to copy the idp_metadata.xml file into the config dir of the elasticsearch install path. How is the current code able to reference this path without a permissions error? Locally (with my PR), I see

java.security.AccessControlException: access denied ("java.io.FilePermission" 
"/Users/archana/Development/apps/elastic/versions/master/kibana/x-pack/
test/saml_api_integration/fixtures/idp_metadata.xml" "read")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You just need to pass it as an absolute path, kbn/es will ensure any absolute path to a file is copied to the config directory before running.

https://github.com/elastic/kibana/blob/master/x-pack/dev-tools/functional_tests/lib/run_es_with_xpack.js#L38

https://github.com/elastic/kibana/blob/master/packages/kbn-es/src/utils/extract_config_files.js

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@rhoboat rhoboat removed the request for review from spalger May 1, 2018 13:23
@rhoboat rhoboat changed the title [X-Pack] Integration test setup (moved from x-pack repo) Integration test setup with kbn-test package May 1, 2018
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@rhoboat
Copy link
Copy Markdown
Author

rhoboat commented May 2, 2018

@tylersmalley ready for your review again, took care of all your concerns. (but there may be more)

@elasticmachine

This comment has been minimized.

@LeeDr
Copy link
Copy Markdown

LeeDr commented May 2, 2018

@archanid I'm confused about the description for running the x-pack functional tests. It looks like both Kibana and the x-pack tests are started with node scripts/functional_tests. But in the first section it says

By default, it runs tests using --config test/functional/config.js,test/api_integration/config.js

and in the x-pack section it says
By default, it runs tests using --config test/multiple_config.js which lists the following two config files

What are the following two config files?

How can the same functional_tests script have 2 different defaults?

Lastly, can we call this issue
Functional test setup with kbn-test package
instead of
Integration test setup with kbn-test package

I tend to think of all of these tests as Functional tests. And the name of the test script is functional_tests.
There are full stack integration tests which include logstash, beats, apm, etc that we call integration tests so I'm just trying to keep the naming clear.

Copy link
Copy Markdown
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your patience @archanid

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@rhoboat rhoboat merged commit b58e757 into elastic:master May 9, 2018
@rhoboat rhoboat deleted the improve-integ-test-xpack branch May 9, 2018 23:30
rhoboat pushed a commit that referenced this pull request May 15, 2018
Restructure testing with kbn-test package

 - Run with multiple configs, move cli options to config
 - Package-ify kbn-test
 - Eventually we'll have functional_test_runner live in a package
of its own, and then this kbn-test will use that as a dependency,
probably still as a devDependency.
 - Implement functional_tests_server
 - Collapse single and multiple config apis into one command

Use kbn-es

Replace es_test_cluster + es_test_config with kbn/test utils

Implement new createEsTestCluster

Improve scripts, jsdocs, cli top-level tools

Lift error handling to the top level
rhoboat pushed a commit that referenced this pull request May 15, 2018
Restructure testing with kbn-test package

 - Run with multiple configs, move cli options to config
 - Package-ify kbn-test
 - Eventually we'll have functional_test_runner live in a package
of its own, and then this kbn-test will use that as a dependency,
probably still as a devDependency.
 - Implement functional_tests_server
 - Collapse single and multiple config apis into one command

Use kbn-es

Replace es_test_cluster + es_test_config with kbn/test utils

Implement new createEsTestCluster

Improve scripts, jsdocs, cli top-level tools

Lift error handling to the top level
spalger added a commit that referenced this pull request May 15, 2018
spalger added a commit that referenced this pull request May 15, 2018
rhoboat pushed a commit that referenced this pull request May 17, 2018
Restructure testing with kbn-test package

 - Run with multiple configs, move cli options to config
 - Package-ify kbn-test
 - Eventually we'll have functional_test_runner live in a package
of its own, and then this kbn-test will use that as a dependency,
probably still as a devDependency.
 - Implement functional_tests_server
 - Collapse single and multiple config apis into one command

Use kbn-es

Replace es_test_cluster + es_test_config with kbn/test utils

Implement new createEsTestCluster

Improve scripts, jsdocs, cli top-level tools

Lift error handling to the top level
@rhoboat rhoboat mentioned this pull request May 17, 2018
12 tasks
@kimjoar kimjoar mentioned this pull request May 17, 2018
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported review Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t//

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants