Skip to content

Proposal: test: implement parallel/serial test categorization system#9224

Merged
tekton-robot merged 1 commit intotektoncd:mainfrom
vdemeester:test/e2e-configmap-isolation
Dec 19, 2025
Merged

Proposal: test: implement parallel/serial test categorization system#9224
tekton-robot merged 1 commit intotektoncd:mainfrom
vdemeester:test/e2e-configmap-isolation

Conversation

@vdemeester
Copy link
Member

@vdemeester vdemeester commented Dec 9, 2025

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 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

Actions

  • Does this approach make sense to you @tektoncd/core-maintainers ?
  • Should we consider unannotated test and parallel the same, and thus only require an annotation for parallel test
  • Should I split this ? The most interested changes is in the init_test.go file - I could split that change from the one that adds the annotations

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Dec 9, 2025
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 9, 2025
@vdemeester
Copy link
Member Author

/kind misc

@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Dec 9, 2025
@vdemeester vdemeester force-pushed the test/e2e-configmap-isolation branch 2 times, most recently from 9e6545a to 0c46b6b Compare December 10, 2025 09:41
@vdemeester
Copy link
Member Author

/cherry-pick foo

@tekton-robot
Copy link
Collaborator

Cherry-pick to foo failed!

The automatic cherry-pick to foo failed.

Output:

🤖 Starting cherry-pick process...
Fetching PR #9224 information...
❌ ERROR: PR #9224 is not merged yet (state: OPEN). Cherry-pick requires merged PRs.

Next steps:

  • Check the action logs for complete details
  • If the PR is not merged, merge it first and try again
  • If there are conflicts, you'll need to manually cherry-pick this PR

@afrittoli
Copy link
Member

Thanks for this. I think that having @test:execution=parallel as default probably makes sense, but I don't mind the extra annotations, they mean that someone took the time to verify that a test can be executed in parallel.

@vdemeester
Copy link
Member Author

Alright, the cherry-pick command is back !

@vdemeester
Copy link
Member Author

Thanks for this. I think that having @test:execution=parallel as default probably makes sense, but I don't mind the extra annotations, they mean that someone took the time to verify that a test can be executed in parallel.

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).

@twoGiants
Copy link
Member

twoGiants commented Dec 16, 2025

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.

Copy link
Member

@twoGiants twoGiants left a comment

Choose a reason for hiding this comment

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

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 Unknown and maybe tags

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))
Copy link
Member

Choose a reason for hiding this comment

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

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. 😸

}

// scanTestAnnotations parses all *_test.go files and extracts test metadata
func scanTestAnnotations(dir string) (*TestManifest, error) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

switch key {
case "execution":
execution = value
case "reason":
Copy link
Member

Choose a reason for hiding this comment

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

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))
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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.

@tekton-robot
Copy link
Collaborator

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 16, 2025
@vdemeester vdemeester force-pushed the test/e2e-configmap-isolation branch 2 times, most recently from 7d8ac0f to 712aadc Compare December 17, 2025 09:29
@afrittoli
Copy link
Member

@twoGiants are you happy for your latest comments to be implemented as follow-ups? If so, I'll lgtm this.

@afrittoli
Copy link
Member

/retest

@vdemeester
Copy link
Member Author

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]>
@vdemeester vdemeester force-pushed the test/e2e-configmap-isolation branch from 712aadc to 9d89b01 Compare December 17, 2025 12:14
@vdemeester
Copy link
Member Author

/retest

@twoGiants
Copy link
Member

twoGiants commented Dec 19, 2025

@twoGiants are you happy for your latest comments to be implemented as follow-ups? If so, I'll lgtm this.

Yes of course 😸 @afrittoli

@afrittoli
Copy link
Member

/retest

@afrittoli
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 19, 2025
@tekton-robot tekton-robot merged commit 791c3a6 into tektoncd:main Dec 19, 2025
49 of 51 checks passed
@vdemeester vdemeester deleted the test/e2e-configmap-isolation branch December 19, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/misc Categorizes issue or PR as a miscellaneuous one. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants