enable seeding of GLOBAL_RNG when running tests #16924
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.
When a test fails, the seed
failseed
of the global RNG is printed. It's then possible to reproduce the failure viajulia runtests.jl failedtest --seed=failseed
.Before running this command, if one then wants to re-run the particular test in another context (e.g. at the REPL while debugging), one can insert in failedtest.jl right before the failing test the following line to dump the RNG state:
write(open("/tmp/RNG_RESTORE.jl", "w"), "copy!(Base.GLOBAL_RNG, $(Base.GLOBAL_RNG))")
. Then to restore the state (e.g. at the REPL):include("/tmp/RNG_RESTORE.jl")
.This almost implements #8339 (comment), except that the state is not printed automatically.
This is not very clean, so I hesitate to document it (and if so, where?).
Note: this depends on
the unmerged#16919 forcopy!
.I am not familiar at all with the file runtests.jl, so careful review is needed.