Monkey patch two dependencies to use /dev/unrandom over /dev/random#23
Open
kaoru wants to merge 1 commit into
Open
Monkey patch two dependencies to use /dev/unrandom over /dev/random#23kaoru wants to merge 1 commit into
kaoru wants to merge 1 commit into
Conversation
This makes the tests 11-encrypt.t and 13-keygen.t run consistently quickly, whereas before they were intermittently much slower. Before: $ for i in $(seq 1 10) ; do prove -b t/11-encrypt.t 2>&1 | grep wallclock ; done Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.67 cusr 0.01 csys = 0.71 CPU) Files=1, Tests=36, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.64 cusr 0.02 csys = 0.70 CPU) Files=1, Tests=36, 80 wallclock secs ( 0.03 usr 0.00 sys + 0.66 cusr 0.01 csys = 0.70 CPU) Files=1, Tests=36, 87 wallclock secs ( 0.04 usr 0.00 sys + 0.55 cusr 0.00 csys = 0.59 CPU) Files=1, Tests=36, 67 wallclock secs ( 0.03 usr 0.00 sys + 0.58 cusr 0.00 csys = 0.61 CPU) Files=1, Tests=36, 89 wallclock secs ( 0.03 usr 0.01 sys + 0.49 cusr 0.02 csys = 0.55 CPU) Files=1, Tests=36, 83 wallclock secs ( 0.03 usr 0.01 sys + 0.65 cusr 0.02 csys = 0.71 CPU) Files=1, Tests=36, 80 wallclock secs ( 0.04 usr 0.01 sys + 0.60 cusr 0.01 csys = 0.66 CPU) Files=1, Tests=36, 34 wallclock secs ( 0.04 usr 0.00 sys + 0.62 cusr 0.03 csys = 0.69 CPU) Files=1, Tests=36, 32 wallclock secs ( 0.02 usr 0.00 sys + 0.54 cusr 0.01 csys = 0.57 CPU) After: $ for i in $(seq 1 10) ; do prove -b t/11-encrypt.t 2>&1 | grep wallclock ; done Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.43 cusr 0.01 csys = 0.46 CPU) Files=1, Tests=36, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.41 cusr 0.00 csys = 0.43 CPU) Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.40 cusr 0.01 csys = 0.43 CPU) Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.00 csys = 0.43 CPU) Files=1, Tests=36, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.42 cusr 0.02 csys = 0.47 CPU) Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.01 csys = 0.44 CPU) Files=1, Tests=36, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.00 csys = 0.43 CPU) Files=1, Tests=36, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.39 cusr 0.01 csys = 0.43 CPU) Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.41 cusr 0.01 csys = 0.45 CPU) Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.41 cusr 0.00 csys = 0.44 CPU)
|
I'm not a developer of the project, but if you're mainly concerned with test cases then I would monkey patch there instead of in the modules themselves. Alternatively, you could write a module that patched when it was loaded to override the other modules, then run something like: The real problem is that these kinds of patches are unsafe and hard to maintain through upstream changes. It would be nice if Crypt::Random::Util would let you set the order, or if the other module would use a shared "our" variable as the source for the random file. Then you could just patch that line instead of rewriting the whole function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proof of concept... I don't recommend or expect you to actually merge this! :-)
This makes the tests 11-encrypt.t and 13-keygen.t run consistently
quickly, whereas before they were intermittently much slower.
Before:
$ for i in $(seq 1 10) ; do prove -b t/11-encrypt.t 2>&1 | grep wallclock ; done
Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.67 cusr 0.01 csys = 0.71 CPU)
Files=1, Tests=36, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.64 cusr 0.02 csys = 0.70 CPU)
Files=1, Tests=36, 80 wallclock secs ( 0.03 usr 0.00 sys + 0.66 cusr 0.01 csys = 0.70 CPU)
Files=1, Tests=36, 87 wallclock secs ( 0.04 usr 0.00 sys + 0.55 cusr 0.00 csys = 0.59 CPU)
Files=1, Tests=36, 67 wallclock secs ( 0.03 usr 0.00 sys + 0.58 cusr 0.00 csys = 0.61 CPU)
Files=1, Tests=36, 89 wallclock secs ( 0.03 usr 0.01 sys + 0.49 cusr 0.02 csys = 0.55 CPU)
Files=1, Tests=36, 83 wallclock secs ( 0.03 usr 0.01 sys + 0.65 cusr 0.02 csys = 0.71 CPU)
Files=1, Tests=36, 80 wallclock secs ( 0.04 usr 0.01 sys + 0.60 cusr 0.01 csys = 0.66 CPU)
Files=1, Tests=36, 34 wallclock secs ( 0.04 usr 0.00 sys + 0.62 cusr 0.03 csys = 0.69 CPU)
Files=1, Tests=36, 32 wallclock secs ( 0.02 usr 0.00 sys + 0.54 cusr 0.01 csys = 0.57 CPU)
After:
$ for i in $(seq 1 10) ; do prove -b t/11-encrypt.t 2>&1 | grep wallclock ; done
Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.43 cusr 0.01 csys = 0.46 CPU)
Files=1, Tests=36, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.41 cusr 0.00 csys = 0.43 CPU)
Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.40 cusr 0.01 csys = 0.43 CPU)
Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.00 csys = 0.43 CPU)
Files=1, Tests=36, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.42 cusr 0.02 csys = 0.47 CPU)
Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.01 csys = 0.44 CPU)
Files=1, Tests=36, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.00 csys = 0.43 CPU)
Files=1, Tests=36, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.39 cusr 0.01 csys = 0.43 CPU)
Files=1, Tests=36, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.41 cusr 0.01 csys = 0.45 CPU)
Files=1, Tests=36, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.41 cusr 0.00 csys = 0.44 CPU)