Hi Paul,
Thanks for you feedback, but you have to explain your thoughts to me
a bit more explicitly.
I am standing at the Copenhagen Perl Mongers booth at LinuxForum in
Copenhagen and yes I am a bit slow too.
As I see your two suggestions for methods, time_atmost is what would
be another name for the sub I have already implemented (time_ok and
its evil twin time_nok).
As for time_atmost, this one troubles me a bit, as I see it would be
fun to include, but it's use is somewhat vague to me :)
Your suggestion for a use of $SIG{ALRM} is very good and will be
implemented prior to the first release, since it seems very essential
and addresses a problem I did not see coming, good thing we have this
list.
jonasbn
On 02/03/2007, at 20.19, Paul LeoNerd Evans wrote:
On Thu, 1 Mar 2007 14:53:50 +0100
"Jonas B. Nielsen" <[EMAIL PROTECTED]> wrote:
time_ok( sub { sleep(1); }, 5, 'Passing test' );
time_ok( sub { sleep(10); }, 5, 'Non-passing test' );
...
So my question is: is this module already on CPAN, or something
similar (better), or should I put mine there?
That looks almost exactly like something I wanted, and ended up
hacking
up using Time::HiRes:
$now = time;
$set->loop_once( 2 );
$took = time - $now;
cmp_ok( $took, '>', 1.9, 'loop_once(2) while waiting takes at least
1.9 seconds' );
cmp_ok( $took, '<', 2.1, 'loop_once(2) while waiting takes no more
than 2.1 seconds' );
It would be nice to have a native Test:: primitive for that.
Consider also
time_atleast( sub { sleep(5); }, 3, 'sleep(5) takes at least 3
seconds' );
time_atmost( sub { sleep(5); }, 6, 'sleep(5) takes no more than
6 seconds' );
Consider also whether to handle $SIG{ALRM} and call alarm( $timeout +
2 ), say... so you could throw a wobbly if the test times out
completely. Though beware that sleep() might be implemented using
alarm() on some platforms. Perhaps make it a tunable variable:
$Test::Time::ALRM = 1;
time_ok( sub { while(1) { } }, 1, 'while loops stop' );
I would hope that will complain after 2 seconds or so.
Be slightly careful of timing imprecision though - I decided to
pull in
Time::HiRes for my specific test, but I don't know whether a generic
"Test::Time" module could justify that.
--
Paul "LeoNerd" Evans
[EMAIL PROTECTED]
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/