File: 2.t

package info (click to toggle)
libtie-hash-expire-perl 0.03-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 68 kB
  • sloc: perl: 162; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

use Test::More;

BEGIN{
	eval "use Time::HiRes qw/time sleep/";

# TODO: It is theoretically possible, though unlikely, that you can get
#	Time::HiRes::time() without getting Time::HiRes::sleep(), and in
#	order to use the HiRes functionality you only need time(), so 
#	this is a little sloppy.  OTOH, I don't really see a good way to 
#	test without a finer grain sleep.  (I know you can get finer grain
#	sleep with a three-argument select, but Time::HiRes knows this and
#	will provide you with sleep() if you have select().  Presumably, 
#	it knows the tricks better than I do.)  So... if you can think of
#	a good way to test without getting sleep, testing patches are
#	welcome.

	if($@){
		plan skip_all	=>	"Time::HiRes isn't available on this system.";
	} else {
		plan tests	=>	3;
	}
}

use_ok('Tie::Hash::Expire');

my %res;
tie %res, 'Tie::Hash::Expire', {'expire_seconds' => 1.5};

$res{foo} = 'bar';
sleep 1.2;
is($res{foo},	'bar',	'fractional sleep lower than expiration');

sleep 0.4;
ok(!defined $res{foo},	'fractional sleep higher than expiration');