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

FR-5793 - Rework tests #161

Merged
merged 17 commits into from
Nov 28, 2023
Merged

FR-5793 - Rework tests #161

merged 17 commits into from
Nov 28, 2023

Conversation

upils
Copy link
Collaborator

@upils upils commented Oct 24, 2023

  • skip long (time > ~20s) tests in short mode
  • get rid of useless subtests wrapping
  • replace defer by t.Cleanup
  • rename some test cases
  • rename saveCWD as restoreCWD
  • remove useless comments
# sudo go test -timeout 0 -v -coverprofile=coverage.out -test.short -covermode=atomic -p 1 -count=1 ./...
[...]
# go tool cover -func coverage.out
[...]
total:											(statements)			83.1%

With 29 excluded tests, we can reach 83.9% coverage in around 7s, with parallelism

Next steps will be to:

  • split the test running in CI in long/short tests
  • find a way to merge resulting coverage files to get an overall coverage
  • generate a "base" chroot for test using the same chroot and reuse it

@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (af3b40a) 90.07% compared to head (0162d00) 90.38%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #161      +/-   ##
==========================================
+ Coverage   90.07%   90.38%   +0.31%     
==========================================
  Files          13       13              
  Lines        2629     3402     +773     
==========================================
+ Hits         2368     3075     +707     
- Misses        229      295      +66     
  Partials       32       32              
Flag Coverage Δ
unittests 90.38% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@upils upils self-assigned this Oct 25, 2023
@upils upils changed the title Rework tests FR-5793 - FR-5793 - Rework tests Oct 25, 2023
@upils upils changed the title FR-5793 - FR-5793 - Rework tests FR-5793 - Rework tests Oct 25, 2023
Base automatically changed from invalid-fstab to main October 26, 2023 07:08
@upils upils marked this pull request as ready for review October 26, 2023 07:58
@upils upils requested a review from sil2100 October 27, 2023 09:19
sil2100
sil2100 previously approved these changes Nov 23, 2023
Copy link
Contributor

@sil2100 sil2100 left a comment

Choose a reason for hiding this comment

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

This is good. I really like the NewBasicChroot() bits, and the attention to detail regarding cleanup afterwards. The short/long test split is a good one as well. I have a question regarding that, but that's more of a curiosity - since the short tests execute so fast that it doesn't actually matter that much.

err := os.Mkdir(workDir, 0755)
asserter.AssertErrNil(err, true)
defer os.RemoveAll(workDir)
t.Parallel()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice feature! From what I recall, the Python regular unittest module couldn't run tests in parallel, for instance. So that's a win.

Copy link
Collaborator Author

@upils upils Nov 23, 2023

Choose a reason for hiding this comment

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

In fact by default Go will run tests in parallel. But only tests from different packages. This option is used to tell that in the same package, some tests can be run in parallel with others of the same package. This is nice in our case because we do not have a lot of packages and most of our tests are gathered in a single one (statemachine).


- name: short tests
if: ${{ matrix.test-scenario == 'short' }}
run: sudo go test -timeout 0 -v -test.short -coverprofile=.coverage/coverage-short.out -covermode=atomic ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work? Since I see some conditionals for when testing.Short() is on. But does this mean that the long tests execute all the long AND short tests? Or is there a way to just get the long ones run?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the "long tests" are also executing the short ones. Unfortunately there is no practical way to exclude short ones. But since short ones takes less than 10s this is negligible comparing to the long ones. Moreover, since I upload the coverage in both cases, this is nice that long tests also cover the short ones so the final coverage is the complete one (and not only the coverage of long tests).

upils added 12 commits November 28, 2023 08:57
- skip long (time > ~20s) tests in short mode
- get rid of useless subtests wrapping
- replace defer by t.Cleanup
- rename some test cases
- rename saveCWD as restoreCWD
- remove useless comments
- Keep on replacing defer with t.Cleanup
- Fix some more test to run smoothly in parallel
- ignore some slow tests in short mode
@upils upils merged commit 8277421 into main Nov 28, 2023
13 checks passed
@upils upils deleted the split-tests branch November 28, 2023 11:24
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.

2 participants