New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unit tests: enforce time limits #19821
Comments
I think this would require us to have async for something like |
@Rexicon226 I believe the build system already spawns subprocesses for testing in parallel - a spawned That said, even if we didn't cancel the test directly and instead only fail after letting it complete (EDIT: turns out also stated in OP), |
This is what I was referring to. This We could set a time limit for the entire test runner process but this is a bad idea because we will loose information about which test it was that timed out. |
AFAIU that would be the responsibility of the parent |
The issue that I see is that we would not know which test was the one hanging (timing out). |
From how I interpret lib/compiler/test_runner.zig (looking at it for the first time), every single test execution is requested by the parent process. |
That's an interesting idea, we could have the "latest" test being ran and we'll know if it times out. In the future I would like have this ability in the test runner itself, To add, I believe we'll need a message type for the amount of time the test spent as well, to have this A real world case I personally have is in the RISC-V backend, it's not uncommon for tests to go into an infinite loop because of incorrect codegen, and I have to manually set a timeout in my wrapper script. |
I propose two enhancements that, together, are aimed at helping developers keep total unit test times below an acceptable threshold.
The first enhancement is to have each unit test have a time limit. This would default to 1 second, and any test could change its own time limit with API such as
std.testing.setCurrentTimeLimit(2.0)
. When runningzig test
orzig build
there would be a flag to scale this number. For example,--test-timeout-scale=2.0
would give twice as much time to each unit test. Idea here is that you would set this value on hosts significantly slower or faster than normal.When the time limit of a unit test is exceeded, the build system will kill the misbehaving test and report it as a timeout.
zig test
would run forever and then report a timeout if it took longer than expected.The second enhancement is a flag for discovering the relative durations of unit tests. Something like
--test-timeout-diagnostics
which would display a sorted list of unit tests by how long they took to run.When this flag is run at the build system level, it would aggregate the data across all sets of unit tests.
This is just a fun side benefit, but
--test-timeout-diagnostics
is what suggestion would be given to folks asking "how do I disable the cache when running tests?" which would encourage, let's be honest, people who are probably doing naughty things in their unit tests, to at least think about how long they are taking to run.The text was updated successfully, but these errors were encountered: