5 use Time::HiRes 'time';
16 # Perhaps nobody will notice if we don't say anything
17 # print "# Warning: I'm testing the timed expiration policy.\n# This will take about thirty seconds.\n";
22 ++$n; print "ok $n\n";
24 require Memoize::Expire;
25 ++$n; print "ok $n\n";
28 # print "Close enough? @_[0,1]\n";
29 abs($_[0] - $_[1]) <= 1;
35 $DEBUG and print "# $t0\n";
40 my $diff = $until - (time() - $t0);
41 $DEBUG and print "# until $until; diff = $diff\n";
43 select undef, undef, undef, $diff;
47 # print "NOW: @_ ", time(), "\n";
51 tie my %cache => 'Memoize::Expire', LIFETIME => 8;
53 SCALAR_CACHE => [HASH => \%cache ],
57 ++$n; print "ok $n\n";
65 print "not " unless close_enough($when{$_}, time());
68 $DEBUG and print "# ", time()-$t0, "\n";
70 # values will now expire at T=8, 11, 14
75 $again{$_} = now($_); # Should be the same as before, because of memoization
81 print "not " unless close_enough($when{$_}, $again{$_});
85 wait_until(9.5); # now(1) expires
86 print "not " unless close_enough(time, $again{1} = now(1));
87 ++$n; print "ok $n\n";
90 foreach (2,3) { # Should not have expired yet.
92 print "not " unless close_enough(scalar(now($_)), $again{$_});
96 wait_until(12.5); # now(2) expires
99 print "not " unless close_enough(time, $again{2} = now(2));
100 ++$n; print "ok $n\n";
103 foreach (1,3) { # 1 is good again because it was recomputed after it expired
105 print "not " unless close_enough(scalar(now($_)), $again{$_});