stas 2004/07/12 16:22:32
Modified: ModPerl-Registry/t closure.t Log: utime is not very granular on win32, use more than 2 seconds delay, but don't sleep, just reset the timestamp to the original value when the test is done Submitted by: Randy Kobes Reviewed by: randyk Revision Changes Path 1.13 +21 -11 modperl-2.0/ModPerl-Registry/t/closure.t Index: closure.t =================================================================== RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/closure.t,v retrieving revision 1.12 retrieving revision 1.13 diff -u -u -r1.12 -r1.13 --- closure.t 11 Jul 2004 04:29:26 -0000 1.12 +++ closure.t 12 Jul 2004 23:22:32 -0000 1.13 @@ -21,6 +21,7 @@ my $file = 'closure.pl'; my $path = catfile $cfg->{vars}->{serverroot}, 'cgi-bin', $file; +my $orig_mtime = (stat($path))[8]; # for all sub-tests in this test, we make sure that we always get onto # the same interpreter. if this doesn't happen we skip the sub-test or @@ -45,7 +46,7 @@ ); # modify the file - sleep_and_touch_file($path); + touch_mtime($path); # it doesn't matter, since the script is not cached anyway my $third = get_body($same_interp, $url); @@ -55,6 +56,8 @@ 1, "never the closure problem", ); + + reset_mtime($path); } { @@ -77,7 +80,7 @@ ); # modify the file - sleep_and_touch_file($path); + touch_mtime($path); # should not notice closure effect on the first request my $third = get_body($same_interp, $url); @@ -87,6 +90,8 @@ 1, "no closure on the first request", ); + + reset_mtime($path); } { @@ -109,7 +114,7 @@ ); # modify the file - sleep_and_touch_file($path); + touch_mtime($path); # modification shouldn't be noticed my $third = get_body($same_interp, $url); @@ -119,17 +124,22 @@ 1, "no reload on modification, the closure problem persists", ); + + reset_mtime($path); +} + +sub touch_mtime { + my $file = shift; + # push the mtime into the future (at least 2 secs to work on win32) + # so ModPerl::Registry will re-compile the package + my $time = time + 5; # make it 5 to be sure + utime $time, $time, $file; } -sub sleep_and_touch_file { +sub reset_mtime { my $file = shift; - # need to wait at least 1 whole sec, so utime() will notice the - # difference. select() has better resolution than 1 sec as in - # sleep() so we are more likely to have the minimal waiting time, - # while fulfilling the purpose - select undef, undef, undef, 1.00; # sure 1 sec - my $now = time; - utime $now, $now, $file; + # reset the timestamp to the original mod-time + utime $orig_mtime, $orig_mtime, $file; } # if we fail to find the same interpreter, return undef (this is not