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

Run unit test shuffled and timed #20374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpagot
Copy link
Contributor

@mpagot mpagot commented Oct 10, 2024

Add two additional commands in the unit-test target:

  1. run the test with --shuffle argument: it randomly change the execution order. Comparing the result with the previous in-order execution can spot test dependency issues.
  2. run test with --timer, parse and order the result to print the test in order of time to run. In can help to spot tests taking too much time as maybe using not "mocked" sleep.

Add two additional commands in the unit-test target:
1. run the test with --shuffle argument: it randomly change the
   execution order. Comparing the result with the previous in-order
   execution can spot test dependency issues.
2. run test with --timer, parse and order the result to print the test
   in order of time to run. In can help to spot tests taking too much
   time as maybe using not "mocked" sleep.
@@ -47,6 +47,8 @@ tidy-full: tools/tidy
.PHONY: unit-test
unit-test:
prove -l -Ios-autoinst/ t/
prove --shuffle -l -Ios-autoinst/ t/
Copy link
Member

Choose a reason for hiding this comment

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

Add two additional commands in the unit-test target:

1. run the test with --shuffle argument: it randomly change the execution order. Comparing the result with the previous in-order execution can spot test dependency issues.

I think it's a good idea to also run tests shuffled but not within the default workflows which should always be consistent and reproducible. Otherwise people will be confused because suddenly their PR starts failing. As long as unit tests are still executed quickly enough you can consider to run those multiple invocations in post-merge tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a good idea to also run tests shuffled but not within the default workflows which should always be consistent and reproducible.

Ok, I'm fine with this. Translating it to "code", does it means to create a dedicated Makefile target about it and move the shuffle command there?

quickly enough
I think so, and last command I added somehow try to also keep UT execution time under control (even if at themoment my command only print out execution time and does not set any threshould)

run those multiple invocations in post-merge tests
Could you please elaborate about it? https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/master/.github/workflows/ci.yml it has both on: [push, pull_request]
Should I move it in one of these github workflow?

$ grep -r push .github | grep -v pull_req
.github/workflows/commit-message-checker.yml:  push:
.github/workflows/deploy.yml:  push:
.github/workflows/shellcheck.yml:  push:
.github/workflows/trufflehog.yml:  push:

Should I just leave it like a makefile target and maybe just document it in the CONTRIBUTE.md file?

Copy link
Member

Choose a reason for hiding this comment

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

probably best to create a dedicated Makefile target and a dedicated workflow definition if you want to follow that at all.

@foursixnine
Copy link
Member

I'm here with @okurz - shuffling makes it harder to figure out what's happening and I fail to see atm the situation with test dependencies (can you enlighten me here? what's the problem you're trying to solve?)

@mpagot
Copy link
Contributor Author

mpagot commented Oct 14, 2024

I'm here with @okurz - shuffling makes it harder to figure out what's happening and I fail to see atm the situation with test dependencies (can you enlighten me here? what's the problem you're trying to solve?)

I was digging in https://perldoc.perl.org/prove and noticed that execution mode. From my experience with other unit testing frameworks, it is a good idea to have UT suite also run in this mode to spot hidden issue in UT implementation (like test 42 works only be chance as test 37 has configured some global variable). I try to probe Test Isolation.

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.

3 participants