Proposal: test: implement parallel/serial test categorization system#9224
Conversation
|
/kind misc |
9e6545a to
0c46b6b
Compare
|
/cherry-pick foo |
|
❌ Cherry-pick to The automatic cherry-pick to Output: Next steps:
|
|
Thanks for this. I think that having |
|
Alright, the cherry-pick command is back ! |
That's kind of my approach on this. I am even willing to make the CI fails if there is an unannotated test (to make sure we keep it organized). |
@vdemeester Yes, just wanted to mention this and then saw your comment. It must be consistent, if the annotations are introduced, they are supposed to be used on every test. Can be a separate follow up PR though. |
twoGiants
left a comment
There was a problem hiding this comment.
Thank you for this great improvement! I bet the e2e tests are less flaky and way faster now 🥇
I have a few suggestions below:
- extract filtering utils
- add unit tests
- drop
Unknownand maybetags
test/init_test.go
Outdated
| filterTests(manifest.Parallel) | ||
| fmt.Fprintf(os.Stderr, "Running %d parallel tests\n", len(manifest.Parallel)) | ||
| if len(manifest.Unknown) > 0 { | ||
| fmt.Fprintf(os.Stderr, "WARNING: %d test(s) without @test:execution annotation\n", len(manifest.Unknown)) |
There was a problem hiding this comment.
I would fail (but earlier in scan test annotations) when Unknown > 0. Same below.
In general I would not allow Unknown and update that below everywhere. 😸
test/init_test.go
Outdated
| } | ||
|
|
||
| // scanTestAnnotations parses all *_test.go files and extracts test metadata | ||
| func scanTestAnnotations(dir string) (*TestManifest, error) { |
There was a problem hiding this comment.
This is a nice little test utility library you wrote which could benefit from some unit (or better integration) tests itself. I would not leave it here but only use here. Put it into /test/annotations or /test/categorization. The functions are independent of *testing.M, which is great. Put also the structs there TestInfo and TestManifest.
I would also add some unit(or actual integration) tests without abstracting the filesystem. It shouldn't be to many and should run quick.
test/init_test.go
Outdated
| switch key { | ||
| case "execution": | ||
| execution = value | ||
| case "reason": |
There was a problem hiding this comment.
Maybe you want to enforce reason if execution is serial?
| } | ||
| fmt.Fprintf(os.Stdout, "\n") | ||
|
|
||
| fmt.Fprintf(os.Stdout, "Serial Tests (%d):\n", len(manifest.Serial)) |
There was a problem hiding this comment.
If serial tests are run first, maybe list them first?
|
|
||
| // @test:execution=serial | ||
| // @test:reason=modifies results-from field in feature-flags ConfigMap | ||
| // @test:tags=results,sidecar,featureflags,stateful |
There was a problem hiding this comment.
Not sure about the tags. What is the specific use case for them?
And if we use them, I'd prefer to have to pick them from an enum or there could be to many similar ones at some point => featureflags,feature-flags,feature_flags, ...
| Just note that the build tags should be `-tags=featureflags`. No newline at end of file | ||
| Just note that the build tags should be `-tags=featureflags`. | ||
|
|
||
| ## Test Categorization: Parallel vs Serial Execution |
There was a problem hiding this comment.
This document should be linked somewhere more visible. Here in the main DEVELOPMENT.md the link to the testing docs README.md is here under point number 5: https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md#developing-and-testing
Very difficult to find. 🙈
I would change it up a bit. Remove point 5 and add a subsection under: https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md#iterating-on-code-changes => named Testing and there I would put the link to the actual testing doc. Something like that.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: twoGiants The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
7d8ac0f to
712aadc
Compare
|
@twoGiants are you happy for your latest comments to be implemented as follow-ups? If so, I'll lgtm this. |
|
/retest |
|
ah lol, I messed up something 😂 |
Add a test categorization system that enables selective execution of e2e tests based on whether they can safely run in parallel or must run serially. This optimizes test execution time while preserving safety for tests that modify shared cluster state. Uses comment annotations to mark tests: - `@test:execution=parallel` - Safe for concurrent execution - `@test:execution=serial` - Must run sequentially (modifies ConfigMaps) - `@test:reason` - Documents why serial execution is required The TestMain function in init_test.go parses these annotations using Go's AST parser and orchestrates test execution: - `-category=parallel` - Run only parallel tests - `-category=serial` - Run only serial tests - `-category=all` - Run serial first, then parallel (with fail-fast) - `-show-tests` - Display test categorization - Faster local development: run parallel tests concurrently - CI optimization: separate parallel and serial test jobs - Safety: prevents test interference from ConfigMap modifications - Self-documenting: annotations explain execution requirements Co-Authored-By: Claude <[email protected]> Signed-off-by: Vincent Demeester <[email protected]>
712aadc to
9d89b01
Compare
|
/retest |
Yes of course 😸 @afrittoli |
|
/retest |
|
/lgtm |
Changes
Add a test categorization system that enables selective execution of e2e tests based on whether they can safely run in parallel or must run serially. This optimizes test execution time while preserving safety for tests that modify shared cluster state.
Uses comment annotations to mark tests:
@test:execution=parallel- Safe for concurrent execution@test:execution=serial- Must run sequentially (modifies ConfigMaps)@test:reason- Documents why serial execution is requiredThe TestMain function in init_test.go parses these annotations using Go's AST parser and orchestrates test execution:
-category=parallel- Run only parallel tests-category=serial- Run only serial tests-category=all- Run serial first, then parallel (with fail-fast)-show-tests- Display test categorizationFaster local development: run parallel tests concurrently
CI optimization: separate parallel and serial test jobs
Safety: prevents test interference from ConfigMap modifications
Self-documenting: annotations explain execution requirements
Actions
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
/kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes