"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/expirations.t" (21 Feb 2022, 3827 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 use strict;
    4 use Test::More tests => 41;
    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 # set&add expiration test
   32 print $sock "set foo 0 3 6\r\nfooval\r\n";
   33 is(scalar <$sock>, "STORED\r\n", "stored foo");
   34 
   35 mem_get_is($sock, "foo", "fooval");
   36 mem_move_time($sock, 3);
   37 mem_get_is($sock, "foo", undef);
   38 
   39 $expire = time() - 1;
   40 print $sock "set foo 0 $expire 6\r\nfooval\r\n";
   41 is(scalar <$sock>, "STORED\r\n", "stored foo");
   42 mem_get_is($sock, "foo", undef, "already expired");
   43 
   44 $expire = time() + 4;
   45 print $sock "set foo 0 $expire 6\r\nfoov+1\r\n";
   46 is(scalar <$sock>, "STORED\r\n", "stored foo");
   47 mem_get_is($sock, "foo", "foov+1");
   48 mem_move_time($sock, 4);
   49 mem_get_is($sock, "foo", undef, "now expired");
   50 
   51 $expire = time() - 20;
   52 print $sock "set boo 0 $expire 6\r\nbooval\r\n";
   53 is(scalar <$sock>, "STORED\r\n", "stored boo");
   54 mem_get_is($sock, "boo", undef, "now expired");
   55 
   56 $expire = -1;
   57 print $sock "set boo 0 $expire 6\r\nbooval\r\n";
   58 is(scalar <$sock>, "STORED\r\n", "stored boo");
   59 mem_get_is($sock, "boo", undef, "now expired");
   60 
   61 print $sock "add add 0 2 6\r\naddval\r\n";
   62 is(scalar <$sock>, "STORED\r\n", "stored add");
   63 mem_get_is($sock, "add", "addval");
   64 
   65 print $sock "add add 0 2 7\r\naddval2\r\n";
   66 is(scalar <$sock>, "NOT_STORED\r\n", "add failure");
   67 mem_move_time($sock, 2);
   68 
   69 print $sock "add add 0 2 7\r\naddval3\r\n";
   70 is(scalar <$sock>, "STORED\r\n", "stored add again");
   71 mem_get_is($sock, "add", "addval3");
   72 
   73 # touch expiration test
   74 print $sock "set tch 0 0 8\r\ntouchval\r\n";
   75 is(scalar <$sock>, "STORED\r\n", "stored tch");
   76 
   77 $expire = time() - 1;
   78 print $sock "touch tch $expire\r\n";
   79 is(scalar <$sock>, "TOUCHED\r\n", "touched tch");
   80 mem_get_is($sock, "touch", undef, "now expired");
   81 
   82 print $sock "set tch 0 0 8\r\ntouchval\r\n";
   83 is(scalar <$sock>, "STORED\r\n", "stored tch");
   84 
   85 $expire = time() + 1;
   86 print $sock "touch tch $expire\r\n";
   87 is(scalar <$sock>, "TOUCHED\r\n", "touched tch");
   88 mem_move_time($sock, 1);
   89 mem_get_is($sock, "touch", undef, "now expired");
   90 
   91 print $sock "set tch 0 0 8\r\ntouchval\r\n";
   92 is(scalar <$sock>, "STORED\r\n", "stored tch");
   93 
   94 $expire = -1;
   95 print $sock "touch tch $expire\r\n";
   96 is(scalar <$sock>, "TOUCHED\r\n", "touched tch");
   97 mem_get_is($sock, "touch", undef, "now expired");
   98 
   99 # get and touch expiration test
  100 print $sock "set gat 0 0 6\r\ngatval\r\n";
  101 is(scalar <$sock>, "STORED\r\n", "stored gat");
  102 
  103 $expire = time() - 1;
  104 print $sock "gat $expire gat\r\n";
  105 is(scalar <$sock>, "VALUE gat 0 6\r\n","get and touch gat");
  106 is(scalar <$sock>, "gatval\r\n","value");
  107 is(scalar <$sock>, "END\r\n", "end");
  108 mem_get_is($sock, "gat", undef, "now expired");
  109 
  110 print $sock "set gat 0 0 6\r\ngatval\r\n";
  111 is(scalar <$sock>, "STORED\r\n", "stored gat");
  112 
  113 $expire = time() + 1;
  114 print $sock "gat $expire gat\r\n";
  115 is(scalar <$sock>, "VALUE gat 0 6\r\n","get and touch gat");
  116 is(scalar <$sock>, "gatval\r\n","value");
  117 is(scalar <$sock>, "END\r\n", "end");
  118 mem_move_time($sock, 1);
  119 mem_get_is($sock, "gat", undef, "now expired");
  120 
  121 
  122 print $sock "set gat 0 0 6\r\ngatval\r\n";
  123 is(scalar <$sock>, "STORED\r\n", "stored gat");
  124 
  125 $expire = -1;
  126 print $sock "gat $expire gat\r\n";
  127 is(scalar <$sock>, "VALUE gat 0 6\r\n","get and touch gat");
  128 is(scalar <$sock>, "gatval\r\n","value");
  129 is(scalar <$sock>, "END\r\n", "end");
  130 mem_get_is($sock, "gat", undef, "now expired");