|
NAMETest::Timer - test module to test/assert response timesVERSIONThe documentation describes version 2.12 of Test::TimerFEATURES
SYNOPSISuse Test::Timer; time_ok( sub { doYourStuffButBeQuickAboutIt(); }, 1, 'threshold of one second'); time_atmost( sub { doYourStuffYouHave10Seconds(); }, 10, 'threshold of 10 seconds'); time_between( sub { doYourStuffYouHave5-10Seconds(); }, 5, 10, 'lower threshold of 5 seconds and upper threshold of 10 seconds'); # Will succeed time_nok( sub { sleep(2); }, 1, 'threshold of one second'); time_atleast( sub { sleep(2); }, 2, 'threshold of one second'); # Will fail after 5 (threshold) + 2 seconds (default alarm) time_ok( sub { while(1) { sleep(1); } }, 5, 'threshold of one second'); $test::Timer::alarm = 6 #default 2 seconds # Will fail after 5 (threshold) + 6 seconds (specified alarm) time_ok( sub { while(1) { sleep(1); } }, 5, 'threshold of one second'); DESCRIPTIONTest::Timer implements a set of test primitives to test and assert test times from bodies of code.The key features are subroutines to assert or test the following:
EXPORTTest::Timer exports:
SUBROUTINES/METHODStime_okTakes the following parameters:
time_nok( sub { sleep(2); }, 1, 'threshold of one second'); If the execution of the code exceeds the threshold specified the test fail with the following diagnostic message Test ran 2 seconds and exceeded specified threshold of 1 seconds time_nokThe 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.The API is the same as for time_ok. time_nok( sub { sleep(1); }, 2, 'threshold of two seconds'); If the execution of the code executes below the threshold specified the test fail with the following diagnostic message Test ran 1 seconds and did not exceed specified threshold of 2 seconds time_atmostThis is syntactic sugar for time_oktime_atmost( sub { doYourStuffButBeQuickAboutIt(); }, 1, 'threshold of one second'); If the execution of the code exceeds the threshold specified the test fail with the following diagnostic message Test ran N seconds and exceeded specified threshold of 1 seconds N will be the actual measured execution time of the specified code time_atleasttime_atleast( sub { doYourStuffAndTakeYourTimeAboutIt(); }, 1, 'threshold of 1 second'); The test succeeds if the code takes at least the number of seconds specified by the timing threshold. If the code executes faster, the test fails with the following diagnostic message Test ran 1 seconds and did not exceed specified threshold of 2 seconds 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. $Test::Timer::alarm = $my_alarm_in_seconds; See also diagnostics. time_betweenThis 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 succeedtime_between( sub { sleep(2); }, 5, 10, 'lower threshold of 5 seconds and upper threshold of 10 seconds'); If the code executes faster than the lower threshold or exceeds the upper threshold, the test fails with the following diagnostic message Test ran 2 seconds and did not execute within specified interval 5 - 10 seconds Or Test ran 12 seconds and did not execute within specified interval 5 - 10 seconds PRIVATE FUNCTIONS_runtestThis 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)._benchmarkThis is the method doing the actual benchmark, if a better method is located this is the place to do the handy work.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. The method takes two parameters:
importTest::Builder required import to do some import hokus-pokus for the test methods exported from Test::Timer. Please refer to the documentation in Test::BuilderDIAGNOSTICSAll tests either fail or succeed, but a few exceptions are implemented, these are listed below.
CONFIGURATION AND ENVIRONMENTThis module requires no special configuration or environment.Tests are sensitive and be configured using environment and configuration files, please see the section on test and quality. DEPENDENCIES
INCOMPATIBILITIESThis module holds no known incompatibilities.BUGS AND LIMITATIONSThis module holds no known bugs.The current implementations only use seconds and resolutions should be higher, so the current implementation is limited to seconds as the highest resolution. 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. TEST AND QUALITYCoverage report for the release described in this documentation (see VERSION).---------------------------- ------ ------ ------ ------ ------ ------ ------ 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 ---------------------------- ------ ------ ------ ------ ------ ------ ------ The Test::Perl::Critic test runs with severity 5 (gentle) for now, please refer to t/critic.t and t/perlcriticrc. Set TEST_POD to enable Test::Pod test in t/pod.t and Test::Pod::Coverage test in t/pod-coverage.t. Set TEST_CRITIC to enable Test::Perl::Critic test in t/critic.t CONTINUOUS INTEGRATIONThis distribution uses Travis for continuous integration testing, the Travis reports are public available.SEE ALSO
ISSUE REPORTINGPlease report any bugs or feature requests using GitHub
SUPPORTYou can find (this) documentation for this module with the "perldoc" command.perldoc Test::Timer You can also look for information at:
DEVELOPMENT
AUTHOR
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHTTest::Timer and related modules are (C) by Jonas Brømsø (jonasbn) 2007-2021Test::Timer and related modules are released under the Artistic License 2.0 Used distributions are under copyright of there respective authors and designated licenses Image used on website <https://jonasbn.github.io/perl-test-timer/> is under copyright by Veri Ivanova <https://unsplash.com/photos/p3Pj7jOYvnM>
Visit the GSP FreeBSD Man Page Interface. |