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

Pass go test flags to integration tests #3109

Merged
merged 8 commits into from
Jul 26, 2023

Conversation

pchila
Copy link
Member

@pchila pchila commented Jul 20, 2023

What does this PR do?

Why is it important?

It allows to propagate go test flags to the actual go test command allowing for finer control over the test execution.
The -test.short is also important for allowing a quicker execution for PRs, for example while maintaining a full integration test run in other contexts.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

Author's Checklist

  • [ ]

How to test this PR locally

Try to run integration tests (both locally and remotely) with some custom go test flags. There are some examples listed in the dev-guide, for example:

We pass a -test.run flag along with the names of the tests we want to run in OR

GOTEST_FLAGS="-test.run ^(TestStandaloneUpgrade|TestFleetManagedUpgrade)$" mage integration:test

Related issues

Use cases

Screenshots

Logs

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@pchila pchila requested a review from a team as a code owner July 20, 2023 15:59
@pchila pchila self-assigned this Jul 20, 2023
@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2023

This pull request does not have a backport label. Could you fix it @pchila? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 20, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-07-26T08:03:38.194+0000

  • Duration: 24 min 28 sec

Test stats 🧪

Test Results
Failed 0
Passed 6127
Skipped 27
Total 6154

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@pchila
Copy link
Member Author

pchila commented Jul 24, 2023

/test

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 24, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.718% (77/78) 👍
Files 68.657% (184/268) 👍
Classes 67.606% (336/497) 👍
Methods 54.222% (1053/1942) 👍
Lines 40.331% (12049/29875) 👍 0.043
Conditionals 100.0% (0/0) 💚

@pierrehilbert pierrehilbert added the Team:Elastic-Agent Label for the Agent team label Jul 24, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@pierrehilbert pierrehilbert added the backport-v8.9.0 Automated backport with mergify label Jul 24, 2023
@mergify mergify bot removed the backport-skip label Jul 24, 2023
magefile.go Outdated Show resolved Hide resolved
@pchila pchila force-pushed the pass-test-flags-to-integration-tests branch from 038ff44 to 4c0a8b9 Compare July 24, 2023 16:14
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Change looks good to me.

magefile.go Outdated Show resolved Hide resolved
@pchila pchila force-pushed the pass-test-flags-to-integration-tests branch from 1bb7bc8 to 5c32270 Compare July 25, 2023 08:04
@pchila
Copy link
Member Author

pchila commented Jul 25, 2023

ok, now integration tests are running correctly after a small change in 5c32270

/cc @ycombinator

@pchila pchila requested a review from belimawr July 25, 2023 09:38
@@ -232,11 +232,10 @@ func GoTest(ctx context.Context, params GoTestArgs) error {
)
}

testArgs = append(testArgs, params.ExtraFlags...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: why was this change needed?

Copy link
Member Author

@pchila pchila Jul 25, 2023

Choose a reason for hiding this comment

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

Sorry for the incoming wall of text 😅

TL;DR: This was needed to make sure that a -test.run flag specified in the GOTEST_FLAGS environment variable does not interfere with the batching done by the framework.

Full explanation:
The integration test framework runs the tests twice:

  • the first time we pass a special tag that make all the define statements in the tests skip the test and dump the requirements. This output is processed by the integration test framework to discover the tests and the set of environments/machines we will need to spawn and allocate the tests to the various machines.
  • the second time we run the tests (here) the integration test framework adds a -test.run flag when launching go test on the remote machine to make sure that only the tests corresponding to that batch are executed.

By specifying the extra flags before the -test.run for the batch we make sure that the last flag definition "wins" (have a look at the unit test in batch_test.go) so that whatever run constraint is specified in GOTEST_FLAGS participates in the discovery and batching (1st go test execution) but doesn't override the actual execution on the remote machine (2nd go test execution).

Copy link
Member

Choose a reason for hiding this comment

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

This should definitely be a comment in the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the comment just above the change.

@@ -1491,7 +1506,7 @@ func integRunner(ctx context.Context, matrix bool, singleTest string) error {
return nil
}

func createTestRunner(matrix bool, singleTest string, batches ...define.Batch) (*runner.Runner, error) {
func createTestRunner(matrix bool, singleTest string, goTestFlags string, batches ...define.Batch) (*runner.Runner, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get rid of the singleTest argument and the corresponding mage integration:single target now that developers could set GOTEST_FLAGS="-test.run ^SingleTestName$ instead? I think it would be less confusing to have just one way to specify which test(s) to run.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could... I am leaving it in, in case the new flags do not behave like we want but we can deprecate them and create a separate issue to clean up

Copy link
Contributor

Choose a reason for hiding this comment

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

I like mage integration:single [testName] it is much clean CLI command to run a test than all the ENV flags being set. I wish we could get mage to take command line arguments for targets. I would prefer to see something like:

mage integration:test -short -name SingleTestName -platform linux/amd64

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, then could we eliminate just the singleTest argument to this function and have mage integration:single [testName] internally setup goTestFlags appropriately?

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

Left a couple of questions and suggestions.

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
@pchila
Copy link
Member Author

pchila commented Jul 25, 2023

/test

1 similar comment
@pchila
Copy link
Member Author

pchila commented Jul 26, 2023

/test

@pchila
Copy link
Member Author

pchila commented Jul 26, 2023

buildkite test this

@pchila pchila merged commit e54b0a2 into elastic:main Jul 26, 2023
mergify bot pushed a commit that referenced this pull request Jul 26, 2023
* Pass go test flags to integration tests
* Update docs/test-framework-dev-guide.md
* Add clarification about ExtraFlags and RunExpr ordering in devtools.GoTest

---------

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
(cherry picked from commit e54b0a2)
@pchila pchila linked an issue Jul 27, 2023 that may be closed by this pull request
pchila added a commit that referenced this pull request Jul 27, 2023
* Pass go test flags to integration tests
* Update docs/test-framework-dev-guide.md
* Add clarification about ExtraFlags and RunExpr ordering in devtools.GoTest

---------

Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
(cherry picked from commit e54b0a2)

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.9.0 Automated backport with mergify enhancement New feature or request skip-changelog Team:Elastic-Agent Label for the Agent team Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration Testing Framework: add support for arbitrary go test flags
7 participants