"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/issue_260.t" (16 Jul 2020, 2369 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 # Issue #260 is a terrible bug.
    3 # In order to run this test:
    4 # * checkout 1.4.15
    5 # * change TAIL_REPAIR_TIME from (3 * 3600) to 3
    6 # Now it should cause an assert. Patches can be tested to fix it.
    7 
    8 use strict;
    9 use Test::More;
   10 use FindBin qw($Bin);
   11 use lib "$Bin/lib";
   12 use MemcachedTest;
   13 
   14 plan skip_all => "Only possible to test #260 under artificial conditions";
   15 exit 0;
   16 plan tests => 11074;
   17 # assuming max slab is 1M and default mem is 64M
   18 my $server = new_memcached();
   19 my $sock = $server->sock;
   20 
   21 # create a big value for the largest slab
   22 my $max = 1024 * 1024;
   23 my $big = 'x' x (1024 * 1024 - 250);
   24 
   25 ok(length($big) > 512 * 1024);
   26 ok(length($big) < 1024 * 1024);
   27 
   28 # set the big value
   29 my $len = length($big);
   30 print $sock "set big 0 0 $len\r\n$big\r\n";
   31 is(scalar <$sock>, "STORED\r\n", "stored big");
   32 mem_get_is($sock, "big", $big);
   33 
   34 # no evictions yet
   35 my $stats = mem_stats($sock);
   36 is($stats->{"evictions"}, "0", "no evictions to start");
   37 
   38 # set many big items, enough to get evictions
   39 for (my $i = 0; $i < 100; $i++) {
   40   print $sock "set item_$i 0 0 $len\r\n$big\r\n";
   41   is(scalar <$sock>, "STORED\r\n", "stored item_$i");
   42 }
   43 
   44 # some evictions should have happened
   45 my $stats = mem_stats($sock);
   46 my $evictions = int($stats->{"evictions"});
   47 ok($evictions == 37, "some evictions happened");
   48 
   49 # the first big value should be gone
   50 mem_get_is($sock, "big", undef);
   51 
   52 # the earliest items should be gone too
   53 for (my $i = 0; $i < $evictions - 1; $i++) {
   54   mem_get_is($sock, "item_$i", undef);
   55 }
   56 
   57 # check that the non-evicted are the right ones
   58 for (my $i = $evictions - 1; $i < $evictions + 4; $i++) {
   59   mem_get_is($sock, "item_$i", $big);
   60 }
   61 
   62 # Now we fill a slab with incrementable items...
   63 for (my $i = 0; $i < 10923; $i++) {
   64   print $sock "set sitem_$i 0 0 1\r\n1\r\n";
   65   is(scalar <$sock>, "STORED\r\n", "stored sitem_$i");
   66 }
   67 
   68 my $stats = mem_stats($sock);
   69 my $evictions = int($stats->{"evictions"});
   70 ok($evictions == 38, "one more eviction happened: $evictions");
   71 
   72 # That evicted item was the first one we put in.
   73 mem_get_is($sock, "sitem_0", undef);
   74 
   75 sleep 15;
   76 
   77 # Now we increment the item which should be on the tail.
   78 # THIS asserts the memcached-debug binary.
   79 print $sock "incr sitem_1 1\r\n";
   80 is(scalar <$sock>, "2\r\n", "incremented to two");
   81 
   82 #my $stats = mem_stats($sock, "slabs");
   83 #is($stats->{"1:free_chunks"}, 0, "free chunks should still be 0");