comparison t/expirations.t @ 0:30782bb1fc04 MEMCACHED_1_2_3

memcached-1.2.3
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 23 Sep 2007 03:58:34 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:30782bb1fc04
1 #!/usr/bin/perl
2
3 use strict;
4 use Test::More tests => 10;
5 use FindBin qw($Bin);
6 use lib "$Bin/lib";
7 use MemcachedTest;
8
9 my $server = new_memcached();
10 my $sock = $server->sock;
11 my $expire;
12
13 sub wait_for_early_second {
14 my $have_hires = eval "use Time::HiRes (); 1";
15 if ($have_hires) {
16 my $tsh = Time::HiRes::time();
17 my $ts = int($tsh);
18 return if ($tsh - $ts) < 0.5;
19 }
20
21 my $ts = int(time());
22 while (1) {
23 my $t = int(time());
24 return if $t != $ts;
25 select undef, undef, undef, 0.10; # 1/10th of a second sleeps until time changes.
26 }
27 }
28
29 wait_for_early_second();
30
31 print $sock "set foo 0 1 6\r\nfooval\r\n";
32 is(scalar <$sock>, "STORED\r\n", "stored foo");
33
34 mem_get_is($sock, "foo", "fooval");
35 sleep(1.5);
36 mem_get_is($sock, "foo", undef);
37
38 $expire = time() - 1;
39 print $sock "set foo 0 $expire 6\r\nfooval\r\n";
40 is(scalar <$sock>, "STORED\r\n", "stored foo");
41 mem_get_is($sock, "foo", undef, "already expired");
42
43 $expire = time() + 1;
44 print $sock "set foo 0 $expire 6\r\nfoov+1\r\n";
45 is(scalar <$sock>, "STORED\r\n", "stored foo");
46 mem_get_is($sock, "foo", "foov+1");
47 sleep(2.2);
48 mem_get_is($sock, "foo", undef, "now expired");
49
50 $expire = time() - 20;
51 print $sock "set boo 0 $expire 6\r\nbooval\r\n";
52 is(scalar <$sock>, "STORED\r\n", "stored boo");
53 mem_get_is($sock, "boo", undef, "now expired");
54