.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Test::Timer 3pm" .TH Test::Timer 3pm "2017-01-04" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::Timer \- test module to test/assert response times .SH "VERSION" .IX Header "VERSION" The documentation in this module describes version 0.18 of Test::Timer .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::Timer; \& \& time_ok( sub { doYourStuffButBeQuickAboutIt(); }, 1, \*(Aqthreshold of one second\*(Aq); \& \& time_atmost( sub { doYourStuffYouHave10Seconds(); }, 10, \*(Aqthreshold of 10 seconds\*(Aq); \& \& time_between( sub { doYourStuffYouHave5\-10Seconds(); }, 5, 10, \& \*(Aqlower threshold of 5 seconds and upper threshold of 10 seconds\*(Aq); \& \& #Will succeed \& time_nok( sub { sleep(2); }, 1, \*(Aqthreshold of one second\*(Aq); \& \& time_atleast( sub { sleep(2); }, 2, \*(Aqthreshold of one second\*(Aq); \& \& #Will fail after 5 (threshold) + 2 seconds (default alarm) \& time_ok( sub { while(1) { sleep(1); } }, 5, \*(Aqthreshold of one second\*(Aq); \& \& $test::Timer::alarm = 6 #default 2 seconds \& \& #Will fail after 5 (threshold) + 6 seconds (specified alarm) \& time_ok( sub { while(1) { sleep(1); } }, 5, \*(Aqthreshold of one second\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Test::Timer implements a set of test primitives to test and assert test times from bodies of code. .PP The key features are subroutines to assert or test the following: .IP "\(bu" 4 that a given piece of code does not exceed a specified time limit .IP "\(bu" 4 that a given piece of code takes longer than a specified time limit and does not exceed another .SH "EXPORT" .IX Header "EXPORT" Test::Timer exports: .IP "\(bu" 4 time_ok .IP "\(bu" 4 time_nok .IP "\(bu" 4 time_atleast .IP "\(bu" 4 time_atmost .IP "\(bu" 4 time_between .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .SS "time_ok" .IX Subsection "time_ok" Takes the following parameters: .IP "\(bu" 4 a reference to a block of code (anonymous sub) .IP "\(bu" 4 a threshold specified as a integer indicating a number of seconds .IP "\(bu" 4 a string specifying a test name .PP .Vb 1 \& time_ok( sub { doYourStuffButBeQuickAboutIt(); }, 1, \*(Aqthreshold of one second\*(Aq); .Ve .PP If the execution of the code exceeds the threshold the test fails .SS "time_nok" .IX Subsection "time_nok" The is the inverted variant of time_ok, it passes if the threshold is exceeded and fails if the benchmark of the code is within the specified timing threshold. .PP The \s-1API\s0 is the same as for time_ok. .PP .Vb 1 \& time_nok( sub { sleep(2); }, 1, \*(Aqthreshold of one second\*(Aq); .Ve .SS "time_atmost" .IX Subsection "time_atmost" This is \fIsyntactic sugar\fR for time_ok .PP .Vb 1 \& time_atmost( sub { doYourStuffButBeQuickAboutIt(); }, 1, \*(Aqthreshold of one second\*(Aq); .Ve .SS "time_atleast" .IX Subsection "time_atleast" .Vb 1 \& time_atleast( sub { sleep(2); }, 1, \*(Aqthreshold of one second\*(Aq); .Ve .PP The test succeeds if the code takes at least the number of seconds specified by the timing threshold. .PP Please be aware that Test::Timer, breaks the execution with an alarm specified to trigger after the specified threshold + 2 seconds, so if you expect your execution to run longer, set the alarm accordingly. .PP .Vb 1 \& $Test::Timer::alarm = $my_alarm_in_seconds; .Ve .PP See also diagnostics. .SS "time_between" .IX Subsection "time_between" This method is a more extensive variant of time_atmost and time_ok, you can specify a lower and upper threshold, the code has to execute within this interval in order for the test to succeed .PP .Vb 2 \& time_between( sub { sleep(2); }, 5, 10, \& \*(Aqlower threshold of 5 seconds and upper threshold of 10 seconds\*(Aq); .Ve .SH "PRIVATE FUNCTIONS" .IX Header "PRIVATE FUNCTIONS" .SS "_runtest" .IX Subsection "_runtest" This is a method to handle the result from _benchmark is initiates the benchmark calling benchmark and based on whether it is within the provided interval true (1) is returned and if not false (0). .SS "_runtest_atleast" .IX Subsection "_runtest_atleast" This is a simpler variant of the method above, it is the author's hope that is can be refactored out at some point, due to the similarity with _runtest. .SS "_benchmark" .IX Subsection "_benchmark" This is the method doing the actual benchmark, if a better method is located this is the place to do the handy work. .PP Currently Benchmark is used. An alternative could be Devel::Timer, but I do not know this module very well and Benchmark is core, so this is used for now. .PP The method takes two parameters: .IP "\(bu" 4 a code block via a code reference .IP "\(bu" 4 a threshold (the upper threshold, since this is added to the default alarm. .SS "_timestring2time" .IX Subsection "_timestring2time" This is the method extracts the seconds from benchmarks timestring and returns it as an integer. .PP It takes the timestring from _benchmark (Benchmark) and returns the seconds part. .SS "import" .IX Subsection "import" Test::Builder required import to do some import \fIhokus-pokus\fR for the test methods exported from Test::Timer. Please refer to the documentation in Test::Builder .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" All tests either fail or succeed, but a few exceptions are implemented, these are listed below. .IP "\(bu" 4 Test did not exceed specified threshold, this message is diagnosis for time_atleast and time_nok tests, which do not exceed their specified threshold. .IP "\(bu" 4 Test exceeded specified threshold, this message is a diagnostic for time_atmost and time_ok, if the specified threshold is surpassed. .Sp This is the key point of the module, either your code is too slow and you should address this or your threshold is too low, in which case you can set it a bit higher and run the test again. .IP "\(bu" 4 Test did not execute within specified interval, this is the diagnostic from time_between, it is the diagnosis if the execution of the code is not between the specified lower and upper thresholds. .IP "\(bu" 4 Insufficient parameters, this is the message if a specified test is not provided with the sufficient number of parameters, consult this documentation and correct accordingly. .IP "\(bu" 4 Execution exceeded threshold and timed out, the exception is thrown if the execution of tested code exceeds even the alarm, which is default 2 seconds, but can be set by the user or is equal to the uppertreshold + 2 seconds. .Sp The exception results in a diagnostic for the failing test. This is a failsafe to avoid that code runs forever. If you get this diagnose either your code is too slow and you should address this or it might be error prone. If this is not the case adjust the alarm setting to suit your situation. .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" This module requires no special configuration or environment. .PP Tests are sensitive and be configured using environment and configuration files, please see the section on test and quality. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" .IP "\(bu" 4 Carp .IP "\(bu" 4 Benchmark .IP "\(bu" 4 Error .IP "\(bu" 4 Test::Builder .IP "\(bu" 4 Test::Builder::Module .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" This module holds no known incompatibilities. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" This module holds no known bugs. .PP As listed on the \s-1TODO,\s0 the current implementations only use seconds and resolutions should be higher, so the current implementation is limited to seconds as the highest resolution. .SH "TEST AND QUALITY" .IX Header "TEST AND QUALITY" Coverage report for the release described in this documentation (see \s-1VERSION\s0). .PP .Vb 7 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \& File stmt bran cond sub pod time total \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \& blib/lib/Test/Timer.pm 91.7 93.8 66.7 88.5 100.0 99.9 90.7 \& ...Timer/TimeoutException.pm 100.0 n/a n/a 100.0 100.0 0.1 100.0 \& Total 93.1 93.8 66.7 90.6 100.0 100.0 92.1 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- .Ve .PP The Test::Perl::Critic test runs with severity 5 (gentle) for now, please refer to \fIt/critic.t\fR and \fIt/perlcriticrc\fR. .PP Set \s-1TEST_POD\s0 to enable Test::Pod test in \fIt/pod.t\fR and Test::Pod::Coverage test in \fIt/pod\-coverage.t\fR. .PP Set \s-1TEST_CRITIC\s0 to enable Test::Perl::Critic test in \fIt/critic.t\fR .SS "\s-1CONTINUOUS INTEGRATION\s0" .IX Subsection "CONTINUOUS INTEGRATION" This distribution uses Travis for continuous integration testing, the Travis reports are public available. .SH "TODO" .IX Header "TODO" .IP "\(bu" 4 Implement higher resolution for thresholds .IP "\(bu" 4 Factor out _runtest_atleast .IP "\(bu" 4 Add more tests to get a better feeling for the use and border cases requiring alarm etc. .IP "\(bu" 4 Rewrite \s-1POD\s0 to emphasize time_atleast over time_ok .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Test::Benchmark .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests either using rt.cpan.org or Github .PP I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .IP "\(bu" 4 Github: .SH "SUPPORT" .IX Header "SUPPORT" You can find (this) documentation for this module with the \f(CW\*(C`perldoc\*(C'\fR command. .PP .Vb 1 \& perldoc Test::Timer .Ve .PP You can also look for information at: .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .IP "\(bu" 4 MetaCPAN .SH "DEVELOPMENT" .IX Header "DEVELOPMENT" .IP "\(bu" 4 Github Repository .SH "AUTHOR" .IX Header "AUTHOR" .IP "\(bu" 4 Jonas B. Nielsen (jonasbn) \f(CW\*(C`\*(C'\fR .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .IP "\(bu" 4 p\-alik, \s-1PR\s0 #4 eliminating warnings during test .IP "\(bu" 4 Kent Fredric, \s-1PR\s0 #7 addressing file permissions .IP "\(bu" 4 Nick Morrott, \s-1PR\s0 #5 corrections to \s-1POD\s0 .IP "\(bu" 4 Bartosz Jakubski, reporting issue #3 .IP "\(bu" 4 Gabor Szabo (\s-1GZABO\s0), suggestion for specification of interval thresholds even though this was obsoleted by the later introduced time_between .IP "\(bu" 4 Paul Leonerd Evans (\s-1PEVANS\s0), suggestions for time_atleast and time_atmost and the handling of \f(CW$SIG\fR{\s-1ALRM\s0}. Also bug report for addressing issue with Debian packaging resulting in release 0.10 .IP "\(bu" 4 brian d foy (\s-1BDFOY\s0), for patch to _run_test .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Test::Timer and related modules are (C) by Jonas B. Nielsen, (jonasbn) 2007\-2016 .PP Test::Timer and related modules are released under the Artistic License 2.0