On Sun, 11 Jul 2004, Stas Bekman wrote:

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

That works - thanks! I had trouble applying it (even on
linux), so applied it by hand - just to verify, here's
what I used:
==========================================================
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        12 Jul 2004 23:06:48 -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,7 @@
         1,
         "never the closure problem",
     );
+    reset_mtime($path);
 }

 {
@@ -77,7 +79,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 +89,7 @@
         1,
         "no closure on the first request",
     );
+    reset_mtime($path);
 }

 {
@@ -109,7 +112,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 +122,21 @@
         1,
         "no reload on modification, the closure problem persists",
     );
+    reset_mtime($path);
 }

-sub sleep_and_touch_file {
+sub touch_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;
+    # 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 reset_mtime {
+    my $file = shift;
+    # 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

=====================================================================
-- 
best regards,
randy


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

Reply via email to