[memcached] bradfitz, r343: adding absolute time expires tests

commits at code.sixapart.com commits at code.sixapart.com
Mon Sep 4 06:05:21 UTC 2006


adding absolute time expires tests

U   trunk/server/test/expirations.t
U   trunk/server/test/lib/MemcachedTest.pm


Modified: trunk/server/test/expirations.t
===================================================================
--- trunk/server/test/expirations.t	2006-09-04 06:00:51 UTC (rev 342)
+++ trunk/server/test/expirations.t	2006-09-04 06:05:18 UTC (rev 343)
@@ -1,13 +1,14 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 3;
+use Test::More tests => 8;
 use FindBin qw($Bin);
 use lib "$Bin/lib";
 use MemcachedTest;
 
 my $server = new_memcached();
 my $sock = $server->sock;
+my $expire;
 
 print $sock "set foo 0 1 6\r\nfooval\r\n";
 is(scalar <$sock>, "STORED\r\n", "stored foo");
@@ -16,10 +17,15 @@
 sleep(1.2);
 mem_get_is($sock, "foo", undef);
 
+$expire = time();
+print $sock "set foo 0 $expire 6\r\nfooval\r\n";
+is(scalar <$sock>, "STORED\r\n", "stored foo");
+mem_get_is($sock, "foo", undef, "already expired");
 
+$expire = time() + 1;
+print $sock "set foo 0 $expire 6\r\nfoov+1\r\n";
+is(scalar <$sock>, "STORED\r\n", "stored foo");
+mem_get_is($sock, "foo", "foov+1");
+sleep 1;
+mem_get_is($sock, "foo", undef, "now expired");
 
-
-
-
-
-

Modified: trunk/server/test/lib/MemcachedTest.pm
===================================================================
--- trunk/server/test/lib/MemcachedTest.pm	2006-09-04 06:00:51 UTC (rev 342)
+++ trunk/server/test/lib/MemcachedTest.pm	2006-09-04 06:05:18 UTC (rev 343)
@@ -17,11 +17,12 @@
     # works on single-line values only.  no newlines in value.
     my ($sock_opts, $key, $val, $msg) = @_;
     my $opts = ref $sock_opts eq "HASH" ? $sock_opts : {};
-    my $sock = ref $sock_opts eq "GLOB" ? $sock_opts : $opts->{sock};
+    my $sock = ref $sock_opts eq "HASH" ? $opts->{sock} : $sock_opts;
+
     my $expect_flags = $opts->{flags} || 0;
-
     my $dval = defined $val ? "'$val'" : "<undef>";
     $msg ||= "$key == $dval";
+
     print $sock "get $key\r\n";
     if (! defined $val) {
         Test::More::is(scalar <$sock>, "END\r\n", $msg);




More information about the memcached-commits mailing list