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";
30 ++$n; print "ok $n\n";
32 require Memoize::Expire;
33 ++$n; print "ok $n\n";
36 # print "Close enough? @_[0,1]\n";
37 abs($_[0] - $_[1]) <= 1;
43 $DEBUG and print "# $t0\n";
48 my $diff = $until - (time() - $t0);
49 $DEBUG and print "# until $until; diff = $diff\n";
51 select undef, undef, undef, $diff;
55 # print "NOW: @_ ", time(), "\n";
59 tie my %cache => 'Memoize::Expire', LIFETIME => 10;
61 SCALAR_CACHE => [HASH => \%cache ],
65 ++$n; print "ok $n\n";
73 print "not " unless close_enough($when{$_}, time());
76 $DEBUG and print "# ", time()-$t0, "\n";
78 # values will now expire at T=10, 14, 18
83 $again{$_} = now($_); # Should be the same as before, because of memoization
89 print "not " unless close_enough($when{$_}, $again{$_});
93 wait_until(12); # now(1) expires
94 print "not " unless close_enough(time, $again{1} = now(1));
95 ++$n; print "ok $n\n";
98 foreach (2,3) { # Should not have expired yet.
100 print "not " unless close_enough(scalar(now($_)), $again{$_});
104 wait_until(16); # now(2) expires
107 print "not " unless close_enough(time, $again{2} = now(2));
108 ++$n; print "ok $n\n";
111 foreach (1,3) { # 1 is good again because it was recomputed after it expired
113 print "not " unless close_enough(scalar(now($_)), $again{$_});