6 eval {require Time::HiRes};
7 if ($@ || $ENV{SLOW}) {
10 'Time::HiRes'->import('time');
24 # Perhaps nobody will notice if we don't say anything
25 # print "# Warning: I'm testing the timed expiration policy.\n# This will take about thirty seconds.\n";
31 ++$n; print "ok $n\n";
34 require Memoize::Expire;
35 ++$n; print "ok $n\n";
38 # print "Close enough? @_[0,1]\n";
39 abs($_[0] - $_[1]) <= 2;
43 # print "Close enough? @_[0,1]\n";
44 abs($_[0] - $_[1]) <= 0.01;
50 $DEBUG and print "# $t0\n";
55 my $diff = $until - (time() - $t0);
56 $DEBUG and print "# until $until; diff = $diff\n";
58 select undef, undef, undef, $diff;
62 # print "NOW: @_ ", time(), "\n";
66 tie my %cache => 'Memoize::Expire', LIFETIME => 15;
68 SCALAR_CACHE => [HASH => \%cache ],
73 ++$n; print "ok $n\n";
82 print "not " unless close_enough($when{$_}, time());
85 $DEBUG and print "# ", time()-$t0, "\n";
87 # values will now expire at T=15, 21, 27
92 $again{$_} = now($_); # Should be the same as before, because of memoization
99 if (very_close($when{$_}, $again{$_})) {
102 print "not ok $n # expected $when{$_}, got $again{$_}\n";
107 wait_until(18); # now(1) expires
108 print "not " unless close_enough(time, $again{1} = now(1));
109 ++$n; print "ok $n\n";
113 foreach (2,3) { # Should not have expired yet.
115 print "not " unless now($_) == $again{$_};
119 wait_until(24); # now(2) expires
123 print "not " unless close_enough(time, $again{2} = now(2));
124 ++$n; print "ok $n\n";
128 foreach (1,3) { # 1 is good again because it was recomputed after it expired
130 if (very_close(scalar(now($_)), $again{$_})) {
133 print "not ok $n # expected $when{$_}, got $again{$_}\n";