Skip to content

Update Unit Tests to run in parallel #27423

Open

Description

@NachoxMacho

Summary

Unit tests are currently sometimes ran in parallel and sometimes ran sequentially. This leads to a lot of tests running up front but still having a relatively long trail of tests which increases the amount of time needed to execute the unit tests. For example, here is CPU usage on my machine during the tests.
Image

DONE 7180 tests, 6 skipped in 106.685s

There's an initial spike of CPU usage, but the second half of the test execution is much lower CPU execution as more tests are ran sequentially.

Motivation

This burns CI time (though not as much as the e2e tests), and slows down developers utilizing the make test functionality. As someone getting into to the codebase I find myself running make test frequently to ensure my changes aren't breaking other parts of the codebase.

I did a brief test using some ugly regex on my machine to get a ballpark number, and saw test runs drop to about a minute (test failures are due to my poor regexing and some tests not functioning in parallel).

DONE 4672 tests, 3 skipped, 1795 failures, 3 errors in 57.099s

Even if we get half the results, that's still saving ~25% of the execution time which seems like a reasonable tradeoff to add parallelism where possible.

Proposal

Where possible, we should be adding t.Parallel() to test functions and test runs. I think to make the work manageable this can be handled similar to #10592 with multiple PRs for smaller chunks to be updated.

Activity

  1. added
    enhancementNew feature or request
    triage/pendingThis issue needs further triage to be correctly classified
    on Apr 18, 2026
  2. added and removed
    triage/pendingThis issue needs further triage to be correctly classified
    on Apr 20, 2026
  3. blakepettersson commented on Apr 20, 2026

    @blakepettersson
    Member

    I did some initial testing and managed to only cut the total exec time down by ~8 seconds locally

    # master
    
    DONE 7178 tests, 6 skipped, 3 failures in 141.650s
    make: *** [test-local] Error 1
    
    # my local branch
    
    DONE 7178 tests, 6 skipped, 3 failures in 133.375s
    make: *** [test-local] Error 1
    

    I excluded ~2k tests which are not trivially parallelizable due to reasons. Perhaps the gains will be much larger if we could fix those ones as well

  4. GuruduGanesh commented on Apr 24, 2026

    @GuruduGanesh
    Contributor

    Hi @NachoxMacho and @blakepettersson , I’d be interested in taking a first pass on this if nobody else is already working on it.

    Given the failure rate from the broad regex-based experiment, I agree this seems best handled in small PRs rather than trying to parallelize everything at once.

    My approach would be to start with one isolated subset of unit tests, review them for shared state or other parallel-safety concerns, add t.Parallel() only where isolation is clear, and then measure the impact before expanding further.

    If that sounds reasonable, I can start with a small, low-risk batch first.

  5. NachoxMacho commented on Apr 29, 2026

    @NachoxMacho
    Author

    I think this is going to take multiple people and quite a few PRs in order to be done, so I don't think we need to worry too much about colliding on work.

    Per the potential benefits, I do think spending time on parallelizing the non-trivial is where more of the benefit is going to be, and it's hard to get specific numbers as each run will be different. Even at an individual package level though, I think we will see more benefits. For example in just the applicationset controller test suite, adding parallelization reduce that unit test from a consistent 6-7 seconds to ~3 seconds.

    Also from some brief analysis using vgt, I see numerous tails like this:
    Image
    Where maybe a test or 2 is able to run in parallel but there is a long line of sequential tests unlike the middle of this where a whole suite of package tests can execute. This isn't the worst one I think small gains over the course of the execution would provide benefit.

  6. blakepettersson commented on May 6, 2026

    @blakepettersson
    Member

    @NachoxMacho I did a bit more experimentation and I managed to cut the time down to ~80s. Great tip in regards to vgt!

  7. blakepettersson commented on May 7, 2026

    @blakepettersson
    Member

    Feel free to work on parallelizing the tests @NachoxMacho @GuruduGanesh

  8. github-actions commented on Aug 6, 2026

    @github-actions
    Contributor

    This issue has been marked as stale because it has had no activity for 90 days. Please comment if this is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleNo activity for over 90 dayscomponent:testTest requests (e2e or unit)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions