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 integration tests #1821

Merged
merged 4 commits into from
Sep 15, 2021
Merged

Refactor integration tests #1821

merged 4 commits into from
Sep 15, 2021

Conversation

chiiph
Copy link
Contributor

@chiiph chiiph commented Aug 26, 2021

Checklist for submitter

If some of the following don't apply, please write a short explanation why.

  • Changes file added (if needed)
  • Documented any API changes
  • Added tests for all functionality
  • Manual QA for all functionality

@chiiph chiiph requested review from zwass, mna and edwardsb August 26, 2021 16:03
Copy link
Member

@zwass zwass left a comment

Choose a reason for hiding this comment

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

I did not get a chance to fully digest this, but I am comfortable moving forward assuming you and @mna agree this is a good new pattern and you are confident all the tests are running as expected.

Comment on lines 20 to 25
// an io.ReadCloser for new request body
type nopCloser struct {
io.Reader
}

func (nopCloser) Close() error { return nil }
Copy link
Member

Choose a reason for hiding this comment

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

I see you copied this from existing code, but let's use https://pkg.go.dev/io/ioutil#NopCloser

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch. Btw, ioutil is deprecated, in this case we should use io.NopCloser.

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2021

Codecov Report

Merging #1821 (b5297f5) into main (0bc485b) will increase coverage by 0.22%.
The diff coverage is 93.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1821      +/-   ##
==========================================
+ Coverage   48.05%   48.27%   +0.22%     
==========================================
  Files         224      225       +1     
  Lines       21266    21375     +109     
==========================================
+ Hits        10219    10319     +100     
- Misses       9832     9840       +8     
- Partials     1215     1216       +1     
Impacted Files Coverage Δ
server/datastore/mysql/testing_utils.go 85.87% <0.00%> (-3.02%) ⬇️
server/service/client.go 16.47% <0.00%> (ø)
server/service/testing_client.go 100.00% <100.00%> (ø)
server/service/testing_utils.go 91.01% <100.00%> (+0.88%) ⬆️
server/datastore/mysql/mysql.go 76.81% <0.00%> (-0.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e968a26...b5297f5. Read the comment docs.

Copy link
Member

@mna mna left a comment

Choose a reason for hiding this comment

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

This looks really good, I think the tests are very readable, top-down, easy to understand what actions get executed and what behaviour is asserted.

Besides the couple minor things I left inline, one thing I'd question (and apologies if that had already been discussed and this ship has sailed) is the use of the testify/suite package vs tests with sub-tests. I think we can fully reproduce the setup/teardown without using a (likely less familiar) third-party for this:

  • the suite-level setup/teardown is simply the code that runs in the top-level Test function and deferred execution (or registered via t.Cleanup)
  • the common-to-all-tests test-level setup/teardown can be a simple setup function to be called on each test and that calls t.Cleanup to register the common teardown (also makes code more explicit vs a special naming convention)
  • a "test suite" would basically be a top-level Test function composed of n sub-tests
  • the suite can still be defined as a struct that holds state if needed, with methods being the subtests, if that makes the code clearer than closures defined in the top-level test

Anyway, not a big deal but I feel like we could make our tests a bit more familiar to contributors, while keeping the main benefits.

server/service/testing_utils.go Outdated Show resolved Hide resolved
server/service/integration_logger_test.go Outdated Show resolved Hide resolved
server/service/integration_enterprise_test.go Outdated Show resolved Hide resolved
server/service/integration_ds_only_test.go Show resolved Hide resolved
@chiiph
Copy link
Contributor Author

chiiph commented Sep 15, 2021

one thing I'd question (and apologies if that had already been discussed and this ship has sailed) is the use of the testify/suite package vs tests with sub-tests.

We haven't discussed it at length. The upside to test suites vs sub-tests is that we can reuse the same suite across multiple files. Which is also true for sub-tests if you define the test function separately, but it's not the pattern we've been following.

Other than that, it's simply that we are already relying on testify, so this simply uses another part of it.

I don't feel super strong in favor of either, to be honest. As long as the tests are readable, handle the evolution of the code gracefully, and are extensible easily... I don't care about the details.

If you feel like these are not good enough arguments to go in this direction, I'm more than happy to switch to sub-tests. You have much more experience with them. It might be important that whatever we decide, though, we follow everywhere. What do you think?

@mna
Copy link
Member

mna commented Sep 15, 2021

Other than that, it's simply that we are already relying on testify, so this simply uses another part of it.

Yeah for assertions (assert/require), I think it helps keep the tests and if conditions to a minimum. It's the rest of the testify repo I'm not sure we need.

I don't feel super strong in favor of either, to be honest.

Me neither, I'm not sure it's worth changing all the existing integration tests.

It might be important that whatever we decide, though, we follow everywhere.

You mean even outside integration tests, we should also use the suites instead of sub-tests? My feeling would be more like it's not a big enough deal to rewrite what we have, and when adding new integration tests to existing suites, keep the same approach (or refactor to sub-tests if you can invest the effort), but new tests outside of the suites would use standard Go tests?

@chiiph
Copy link
Contributor Author

chiiph commented Sep 15, 2021

You mean even outside integration tests, we should also use the suites instead of sub-tests? My feeling would be more like it's not a big enough deal to rewrite what we have, and when adding new integration tests to existing suites, keep the same approach (or refactor to sub-tests if you can invest the effort), but new tests outside of the suites would use standard Go tests?

No, not everything. Things that depend on third party services (eg mysql), the more clustered like this we can make them, the faster they will run. More like a recommendation than a rule though.

@mna
Copy link
Member

mna commented Sep 15, 2021

Ok, I will likely tackle the mysql-related tests for the ticket on slow tests, and my plan was to do it with sub-tests, we can discuss then how we feel about those and this other approach? Basically, my hesitation is on using in a third-party package that I think might not bring enough value (even if it's in a repo we already use for other packages, we don't have to use that particular package).

@chiiph
Copy link
Contributor Author

chiiph commented Sep 15, 2021

my plan was to do it with sub-tests, we can discuss then how we feel about those and this other approach?

Sure! Let's see how that looks.

@chiiph chiiph requested review from mna and zwass September 15, 2021 18:33
Copy link
Member

@mna mna left a comment

Choose a reason for hiding this comment

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

As mentioned in standup, I don't think the remaining question about using or not testify/suite should be a blocker, worst case we go back and change it to sub-tests, or we keep it around and address only when we change/add something, or we just go with it definitely. Tests are definitely looking good and super readable! 👍

@chiiph chiiph merged commit e6368cc into main Sep 15, 2021
@chiiph chiiph deleted the better-integration-tests branch September 15, 2021 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants