9 eval {require Time::HiRes};
10 if ($@ || $ENV{SLOW}) {
13 'Time::HiRes'->import('time');
27 # Perhaps nobody will notice if we don't say anything
28 # print "# Warning: I'm testing the timed expiration policy.\n# This will take about thirty seconds.\n";
33 ++$n; print "ok $n\n";
35 require Memoize::Expire;
36 ++$n; print "ok $n\n";
39 # print "Close enough? @_[0,1]\n";
40 abs($_[0] - $_[1]) <= 1;
46 $DEBUG and print "# $t0\n";
51 my $diff = $until - (time() - $t0);
52 $DEBUG and print "# until $until; diff = $diff\n";
54 select undef, undef, undef, $diff;
58 # print "NOW: @_ ", time(), "\n";
62 tie my %cache => 'Memoize::Expire', LIFETIME => 10;
64 SCALAR_CACHE => [HASH => \%cache ],
68 ++$n; print "ok $n\n";
76 print "not " unless close_enough($when{$_}, time());
79 $DEBUG and print "# ", time()-$t0, "\n";
81 # values will now expire at T=10, 14, 18
86 $again{$_} = now($_); # Should be the same as before, because of memoization
92 print "not " unless close_enough($when{$_}, $again{$_});
96 wait_until(12); # now(1) expires
97 print "not " unless close_enough(time, $again{1} = now(1));
98 ++$n; print "ok $n\n";
101 foreach (2,3) { # Should not have expired yet.
103 print "not " unless close_enough(scalar(now($_)), $again{$_});
107 wait_until(16); # now(2) expires
110 print "not " unless close_enough(time, $again{2} = now(2));
111 ++$n; print "ok $n\n";
114 foreach (1,3) { # 1 is good again because it was recomputed after it expired
116 print "not " unless close_enough(scalar(now($_)), $again{$_});