.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" 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 "2022-10-13" "perl v5.34.0" "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 describes version 2.12 of Test::Timer .SH "FEATURES" .IX Header "FEATURES" .IP "\(bu" 4 Test subroutines to implement unit-tests to time that your code executes before a specified threshold .IP "\(bu" 4 Test subroutines to implement unit-tests to time that your code execution exceeds a specified threshold .IP "\(bu" 4 Test subroutine to implement unit-tests to time that your code executes within a specified time frame .IP "\(bu" 4 Supports measurements in seconds .IP "\(bu" 4 Implements configurable alarm signal handler to make sure that your tests do not execute forever .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_nok( sub { sleep(2); }, 1, \*(Aqthreshold of one second\*(Aq); .Ve .PP If the execution of the code exceeds the threshold specified the test fail with the following diagnostic message .PP .Vb 1 \& Test ran 2 seconds and exceeded specified threshold of 1 seconds .Ve .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(1); }, 2, \*(Aqthreshold of two seconds\*(Aq); .Ve .PP If the execution of the code executes below the threshold specified the test fail with the following diagnostic message .PP .Vb 1 \& Test ran 1 seconds and did not exceed specified threshold of 2 seconds .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 .PP If the execution of the code exceeds the threshold specified the test fail with the following diagnostic message .PP .Vb 1 \& Test ran N seconds and exceeded specified threshold of 1 seconds .Ve .PP N will be the actual measured execution time of the specified code .SS "time_atleast" .IX Subsection "time_atleast" .Vb 1 \& time_atleast( sub { doYourStuffAndTakeYourTimeAboutIt(); }, 1, \*(Aqthreshold of 1 second\*(Aq); .Ve .PP The test succeeds if the code takes at least the number of seconds specified by the timing threshold. .PP If the code executes faster, the test fails with the following diagnostic message .PP .Vb 1 \& Test ran 1 seconds and did not exceed specified threshold of 2 seconds .Ve .PP Please be aware that Test::Timer, breaks the execution with an alarm specified to trigger after the specified threshold + 2 seconds (default), 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 .PP If the code executes faster than the lower threshold or exceeds the upper threshold, the test fails with the following diagnostic message .PP .Vb 1 \& Test ran 2 seconds and did not execute within specified interval 5 \- 10 seconds .Ve .PP Or .PP .Vb 1 \& Test ran 12 seconds and did not execute within specified interval 5 \- 10 seconds .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 "_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 "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 upper threshold + 2 seconds .Sp The exception results in a diagnostic for the failing test. This is a fail-safe 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 The current implementations only use seconds and resolutions should be higher, so the current implementation is limited to seconds as the highest resolution. .PP On occasion failing tests with CPAN-testers have been observed. This seem to be related to the test-suite being not taking into account that some smoke-testers do not prioritize resources for the test run and that additional processes/jobs are running. The test-suite have been adjusted to accommodate this but these issues might reoccur. .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 100.0 100.0 100.0 100.0 100.0 99.9 100.0 \& ...Timer/TimeoutException.pm 100.0 n/a n/a 100.0 100.0 0.0 100.0 \& Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- \-\-\-\-\-\- .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 "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Test::Benchmark .SH "ISSUE REPORTING" .IX Header "ISSUE REPORTING" Please report any bugs or feature requests using GitHub .IP "\(bu" 4 GitHub Issues .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 Homepage .IP "\(bu" 4 MetaCPAN .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .SH "DEVELOPMENT" .IX Header "DEVELOPMENT" .IP "\(bu" 4 GitHub Repository , please see the guidelines for contributing . .SH "AUTHOR" .IX Header "AUTHOR" .IP "\(bu" 4 Jonas Bro\*/mso\*/ (jonasbn) \f(CW\*(C`\*(C'\fR .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .IP "\(bu" 4 Mohammad S Anwar (\s-1MANWAR\s0), \s-1POD\s0 corrections PRs #23 .IP "\(bu" 4 Erik Johansen (\s-1UNIEJO\s0), suggestion for clearing alarm .IP "\(bu" 4 Gregor Herrmann (\s-1GREGOA\s0) from the Debian Perl Group, \s-1PR\s0 #16 fixes to spelling mistakes .IP "\(bu" 4 Nigel Horne (\s-1NHORNE\s0), issue #15 suggestion for better assertion in time_atleast .IP "\(bu" 4 Nigel Horne (\s-1NHORNE\s0), issue #10/#12 suggestion for improvement to diagnostics .IP "\(bu" 4 p\-alik, \s-1PR\s0 #4 eliminating warnings during test .IP "\(bu" 4 Kent Fredric (\s-1KENTNL\s0), \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-1SZABGAB\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 _runtest .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Test::Timer and related modules are (C) by Jonas Bro\*/mso\*/ (jonasbn) 2007\-2021 .PP Test::Timer and related modules are released under the Artistic License 2.0 .PP Used distributions are under copyright of there respective authors and designated licenses .PP Image used on website is under copyright by Veri Ivanova