Description
Spec examples are individual pieces of work and by their nature very deterministic. Their execution characteristics are usually relatively predictable.
For example, most typical unit tests should complete within a couple of milliseconds, it not less. If a spec takes significantly longer than the usual time, it's an indicator that something is odd. Sometimes spec code gets messed up and will never complete. It may even lead to the entire process hanging up and never completing.
A timout for limiting execution time on single examples could prevent that.
We're already running stdlib's spec suite with a - considerably generous - timeout for every single spec when builing with -Dpreview_mt
(see #9865). This shoots down any spec if it gets tangled up.
As previously mentioned in #12860 it might be a good idea to elevate this timeout to a proper feature of the spec library, used in all environments. It surely could be useful in other general scenarios as well.
For reference
JUnit
has a timeout feature: https://junit.org/junit5/docs/5.5.1/api/org/junit/jupiter/api/Timeout.html- In stdlib specs we're using two helpers,
wait_for
andschedule_timeout
which also deal with timeouts. Their purposes should be considered as well, although it could be possible that they keep working as independent items if their functionality cannot be provided by a more broadly scoped timeout.
Design details (e.g. API and default configuration) are up to further exploration.