[testscripts] run in parallel #802
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
testscripts
can be run 2x faster. Specifically, time reduces from 30 seconds to 16 seconds.the problem is:
RunTestscripts
function oftestrunner.go
, we callt.Run()
which callstestscript.Run
testscript.Run
, the framework callst.Run()
witht.Parallel()
.The old way would run testscripts within the same sub-directory in parallel, but now we run all the testscripts in parallel.
The reason for this is:
When the golang test framework is executing a sub-test via
t.Run
, it will start executing it until it hits at.Parallel()
. It will then pause this sub-test. It then starts the next sub-test. And so on. Finally, it will resume all paused sub-tests which hadt.Parallel()
and run them concurrently.By injecting the extra
t.Run
for each sub-directory we are limiting the parallellism.ref. https://engineering.mercari.com/en/blog/entry/20220408-how_to_use_t_parallel/
Downside
If two testscripts have the same name, they'll be harder to tell apart in the test framework's output. For example, if we have two testscripts called
info.test.txt
, then their output appears as:This is entirely due to how testscript sets the sub-test's name. I couldn't think of a clever way of overriding that other than "copy all testscripts into a temp-dir and rename them to
<dir>_<subdir1>_<subdir2>_<scriptname>.test.txt
.This downside doesn't currently happen since all our testscripts happen to be uniquely named.
How was it tested?
new output:
old output: