Upgrade to Memoize 0.66.
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / expire_module_t.t
index 7032f65..3cc3de1 100644 (file)
@@ -2,7 +2,15 @@
 
 use lib '..';
 use Memoize;
-use Time::HiRes 'time';
+BEGIN {
+  eval {require Time::HiRes};
+  if ($@ || $ENV{SLOW}) {
+#    $SLOW_TESTS = 1;
+  } else {
+    'Time::HiRes'->import('time');
+  }
+}
+
 my $DEBUG = 0;
 
 my $n = 0;
@@ -48,7 +56,7 @@ sub now {
   time;
 }
 
-tie my %cache => 'Memoize::Expire', LIFETIME => 8;
+tie my %cache => 'Memoize::Expire', LIFETIME => 10;
 memoize 'now',
     SCALAR_CACHE => [HASH => \%cache ],
     LIST_CACHE => 'FAULT'
@@ -64,42 +72,42 @@ for (1,2,3) {
   ++$n;
   print "not " unless close_enough($when{$_}, time());
   print "ok $n\n";
-  sleep 3 if $_ < 3;
+  sleep 4 if $_ < 3;
   $DEBUG and print "# ", time()-$t0, "\n";
 }
-# values will now expire at T=8, 11, 14
-# it is now T=6
+# values will now expire at T=10, 14, 18
+# it is now T=8
 
-# T+6
+# T+8
 for (1,2,3) {
   $again{$_} = now($_); # Should be the same as before, because of memoization
 }
 
-# T+6
+# T+8
 foreach (1,2,3) {
   ++$n;
   print "not " unless close_enough($when{$_}, $again{$_});
   print "ok $n\n";
 }
 
-wait_until(9.5);  # now(1) expires
+wait_until(12);  # now(1) expires
 print "not " unless close_enough(time, $again{1} = now(1));
 ++$n; print "ok $n\n";
 
-# T+9.5
+# T+12
 foreach (2,3) {                        # Should not have expired yet.
   ++$n;
   print "not " unless close_enough(scalar(now($_)), $again{$_});
   print "ok $n\n";
 }
 
-wait_until(12.5);  # now(2) expires
+wait_until(16);  # now(2) expires
 
-# T+12.5
+# T+16
 print "not " unless close_enough(time, $again{2} = now(2));
 ++$n; print "ok $n\n";
 
-# T+12.5
+# T+16
 foreach (1,3) {  # 1 is good again because it was recomputed after it expired
   ++$n;
   print "not " unless close_enough(scalar(now($_)), $again{$_});