Randy Kobes wrote:
On Sat, 10 Jul 2004, Stas Bekman wrote:


Randy Kobes wrote:

I noticed on Win32 there's a problem (what else is new :)
occasionally with the ModPerl-Registry/t/closure.t test;
subtest 4 fails, although not in a reliable manner. I think
this is due to the use of utime in the test to change the
access and modification time; in perlport, it mentions that
utime is unpredictable on Win32. Is using touch() of
ExtUtils::Command:

[ ... ]

equivalent? The doc for utime says it's equivalent to
touch() if the file exists, but is this enough for the test?

It looks like it, but I don't like the use of $^X and external shell calls. How about we simply open the file for append or readwrite and then close it right away? That should be the most portable touch, no?


That's true - how about the following (borrowed from
ExtUtils::Command::touch(), where they open the file and
also use utime)? Also, I changed the wait time in the select
to 2 s, which perlport for utime suggests would work better
on Win32.
============================================================
Index: ModPerl-Registry/t/closure.t
===================================================================
RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/closure.t,v
retrieving revision 1.12
diff -u -r1.12 closure.t
--- ModPerl-Registry/t/closure.t        11 Jul 2004 04:29:26 -0000      1.12
+++ ModPerl-Registry/t/closure.t        11 Jul 2004 17:28:11 -0000
@@ -5,6 +5,7 @@
 use Apache::TestUtil;
 use Apache::TestRequest;
 use File::Spec::Functions;
+use Symbol ();

 # this test tests how various registry packages cache and flush the
 # scripts their run, and whether they check modification on the disk
@@ -127,8 +128,11 @@
     # 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
+    select undef, undef, undef, 2.00; # sure 2 sec
     my $now = time;
+    my $fh = Symbol::gensym();
+    open $fh, ">>$file" or die "Cannot append to $file: $!";

this is 5.6+, no need for Symbol::gensym(); But my suggestion was wrong, for some reason I thought that opening for >> or +> will alter the mod timestamp. This doesn't work.


+    close $fh;
     utime $now, $now, $file;

Actually we don't need to sleep at all, just give more secs over the current time to utime. How about this patch:


Index: ModPerl-Registry/t/closure.t
===================================================================
RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/closure.t,v
retrieving revision 1.12
diff -u -r1.12 closure.t
--- ModPerl-Registry/t/closure.t        11 Jul 2004 04:29:26 -0000      1.12
+++ ModPerl-Registry/t/closure.t        11 Jul 2004 19:36:25 -0000
@@ -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



--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to