As I now understand your problem, we still do not have a solution. You use one (or more) existing module(s) which call sleep(). You wish to include the module sleep time(s) in your total. I devised the following test:
C:\Users\Bill\forums\monks>type Existing_module.pm
use strict;
use warnings;
package Existing_Module;
sub Do_Something {
print "Doing something.\n";
sleep(3);
}
1
C:\Users\Bill\forums\monks>type bliako.t
use strict;
use warnings;
use lib '.';
use Test::More tests => 2;
use Existing_Module;
our $total_sleep_time;
BEGIN {
*actual_sleep = *CORE::sleep;
*CORE::GLOBAL::sleep = sub (;$) {
$total_sleep_time+=$_[0];
actual_sleep($_[0])
}
}
sleep(2);
is($total_sleep_time, 2, 'Local');
Existing_Module::Do_Something(); # Sleeps for 3 sec.
is($total_sleep_time, 2+3, 'Module');
C:\Users\Bill\forums\monks>perl bliako.t
1..2
ok 1 - Local
Doing something.
not ok 2 - Module
# Failed test 'Module'
# at bliako.t line 21.
# got: '2'
# expected: '5'
# Looks like you failed 1 test of 2.
Several proposed solutions (including my previous post) can pass the first test. I have not found any that can pass the second. I have learned not to say that anything is impossible, but it does seem that this is intended to be.
|