Repository navigation
๐๐ This release focuses on speed, again: test cases can now run at the same time with --parallel, and together with the reuse of the function containers a run takes a fraction of the time. Also, xprin test now stops gracefully on Ctrl-C.
๐จ Breaking changes
needsis the only way to depend on a test case. A test case that uses the outputs of another one (.Tests.<id>) without listing it inneedsnow fails withone or more test cases are used but are not listed in needs. 0.6 only warned. Runxprin-helpers check-testsuite-needs <targets>to find what is missing, see Migrating from xprin 0.5 and Earlier. See #170 #175 #206.- With container reuse on, xprin ignores the
runtime-docker-*annotations that aFunctionsets. It manages the name, the cleanup and the network of the containers itself, because reuse only works when it controls them. 0.6 warned about it. Use--no-container-reuseto keep them, see Migrating from User-Set Container Annotations. See #209 #213 #223. - The
Makefileis removed. It was deprecated in 0.6: useearthly +reviewableinstead, seeCONTRIBUTING.md. #242
๐ Highlights
New Features
--parallelruns the test cases at the same time.xprin test -p N(or--parallel=N) runs up to N test cases at the same time, across all the testsuite files, and--parallelalone runs as many as there are CPUs. A test case still waits for the ones it lists inneeds. Without the flag nothing changes. The benchmarks are below. See #94 #236.- The output is the one of a serial run, apart from the timings: the results come in the same order.
--debugis in order, and is not live. With more than one test case at a time, theDEBUG:lines of a test case are printed with its result, so the lines of two test cases never mix.- A failure doesn't stop the run, and the test cases are assumed independent apart from
needs: what two hooks share, like a file or a port, is not a dependency. xprin update-goldenshas no flag.
xprin teststops gracefully on Ctrl-C and SIGTERM. A stopped run used to leave behind containers, networks and temporary directories, which matters more with--parallel. Now the test cases that are running finish, so thatcrossplane renderandcrossplane validateremove their containers, no other test case starts (the file is reported asFAIL <file> [interrupted]), and the cleanup runs. A second signal quits at once, without the cleanup. See #239 #240.
Fixes
- The time of a testsuite file is measured from its first test case. The line of a file (
ok <file> 1.234s) used to count from when the result of the file was made, a little before its first test case. It is now from the start of the first test case to the end of the last one, so it does not depend on when the file was set up, scheduled or reported. With--parallelthe test cases of different files run at the same time, so the times of the files can overlap, and they do not add up to the time of the run. The time of each test case is not changed. #235 - The first use of a function container is serialized. The first render that uses an image creates its container, and the renders that start at the same time and use it wait for that one, instead of Docker refusing the second of two renders that create the same container. #224
Documentation
how-it-works.mdhas two new sections, Parallel Execution and Speed.architecture.mdhas two new sections, Scheduling and Stopping a Run.getting-started.mdand the examples cover--parallel.
๐ Benchmarks
How much faster? On this repository's own examples (xprin test examples/mytests/..., 78 test cases in 25 testsuite files, mean of 3 runs, Crossplane CLI v2.5.0, a laptop with 11 CPUs):
| No reuse, serial (v0.4 and earlier) | Reuse, serial (v0.5 - v0.6) | No reuse, --parallel |
Reuse, --parallel (v0.7) |
|
|---|---|---|---|---|
| Time | 62.4 s | 35.0 s | 16.6 s | 9.8 s |
| Speedup | 1.00x | 1.78x | 3.76x | 6.38x |
Reuse together with --parallel is 3.6x faster than reuse alone, and 6.4x faster than before the reuse. The no-reuse columns are this build with --no-container-reuse, which is how 0.4 ran. The spread of the runs ((max - min) / mean) is about 2%, except for no reuse with --parallel (7%).
What it costs. For the same run, with reuse 52 containers are created instead of 150 (-65%), and with --parallel at most 9 containers run at the same time, against 32 without reuse (sampled four times a second, so a lower bound).
Throughput. A smaller suite (1_simple_tests and 2_multiple_testcases, 8 test cases, mean of 5 runs) shows when each test case ends. The first test case takes about a second in all of them: it has to start the containers, and neither the reuse nor --parallel makes that faster. The gain is in the test cases after it. The total is 10.5 s with no reuse and serial, 6.2 s with reuse and serial, and 2.4 s with reuse and --parallel (4.3x).
Adding test cases. 1 to 16 copies of a testsuite with 2 independent test cases (2 to 32 test cases, mean of 3 runs):
With 32 test cases a run takes 48.3 s with no reuse and serial, 29.4 s with reuse and serial, and 6.9 s with reuse and --parallel. Each test case that is added costs 1.50 s, 0.89 s and 0.16 s respectively. It still grows with the number of test cases, only much more slowly.
Limits seen while measuring. Without reuse every render creates its own Docker network, and with --parallel many are created at once. With enough of them, or with networks left over from killed runs, Docker can answer all predefined address pools have been fully subnetted and the renders fail. The runs above, with no reuse and --parallel, peaked at 32 containers and worked. With reuse (the default) a run needs a third of the containers, so this is another reason to leave it on.
The full benchmarks, how it works, and how to reproduce them are in #236.
What's Changed
- feat!: remove the automatic detection of the dependencies between test cases by @tampakrap in #206
- refactor: make the shared state safe for concurrent use, and run the unit tests with -race by @tampakrap in #207
- feat(containers)!: ignore user-defined function container annotations by @tampakrap in #223
- feat(containers): serialize the first use of a function container by @tampakrap in #224
- refactor: prepare the runner and Walk for running test cases at the same time by @tampakrap in #225
- test(runner): restructure the unit tests to match the phases by @tampakrap in #226
- refactor(discovery): remove DeferFail, Walk never prints the final FAIL by @tampakrap in #229
- feat(scheduler): introduce a scheduler for running test cases by @tampakrap in #227
- feat(processor): run the test cases of all the files with one scheduler by @tampakrap in #230
- feat(runner): print the --debug lines of a test case with its result by @tampakrap in #231
- refactor: use a log.Logger for the --debug lines, made once in the options by @tampakrap in #232
- refactor: split the state of a testsuite file (session) from the run of a test case (runner) by @tampakrap in #233
- fix(engine): measure the duration of a file from its test cases by @tampakrap in #235
- fix(deps): update module github.com/alecthomas/kong to v1.17.0 by @renovate[bot] in #214
- chore(deps): update github actions by @renovate[bot] in #228
- chore(deps): update golang version to v1.27.4 by @renovate[bot] in #234
- feat(test): add
--parallelto run the test cases at the same time by @tampakrap in #236 - chore(deps): update module golang.org/x/crypto to v0.59.0 [security] by @renovate[bot] in #237
- build(version): derive dev version from release branches by @tampakrap in #238
- feat(test): stop gracefully on Ctrl-C and SIGTERM by @tampakrap in #240
- chore: smaller comments by @tampakrap in #241
- build(Makefile): Remove Makefile by @tampakrap in #242
Full Changelog: v0.6.0...v0.7.0