Skip to content

proposal: cmd/test: add flag to run tests in parallel by default #24335

Closed
@posener

Description

@posener

Summary

Following #21214

Add to the go test command a flag --default-parallel or similar, that would run all the tests in parallel - like the current t.Parallel() function behavior, until a t.Serial() or t.Serial(reason string) functions where invoked.

Details

When the new flag will be given, the test runner will invoke all the test functions and will skip the wait part before executing the next test function. Once a t.Serial function will be called in the test function, the go routing running the current test will be stopped and will be added to a serial tests queue. Once all the parallel test were done, test functions from the the serial queue will be invoked in a synchronous way.

When the flag --default-parallel won't be given, the t.Serial function will have no effect, and tests behavior will maintain it's current form.

Backward Compatibility

As far as I can see, this is not a breaking change.

Reason

The reason why this change can contribute to the language are given in #21214:

  • Faster tests: running all possible tests in parallel will result in shorter test time.
  • Explicitly: Having a programmer write an explicit reason for the test not to be able run in parallel: t.Serial("Modifies a database which is used by several tests").
  • Bugs detection: running tests in parallel is one of the ways to detect bugs in program design, which might be hidden in a serial invocation of the tests.
  • Less code/ Programmer friendlier: almost every test deceleration takes two lines of code: the test function deceleration and a following line t.Parallel(). It is a common case to see only the first, and the main reason for that is the the programmer forgot to type the second.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions