"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/flush-all.t" (21 Feb 2022, 3193 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 => 27;
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 print $sock "set foo 0 0 6\r\nfooval\r\n";
14 is(scalar <$sock>, "STORED\r\n", "stored foo");
15
16 mem_get_is($sock, "foo", "fooval");
17 print $sock "flush_all\r\n";
18 is(scalar <$sock>, "OK\r\n", "did flush_all");
19 mem_get_is($sock, "foo", undef);
20
21 # Test flush_all with zero delay.
22 print $sock "set foo 0 0 6\r\nfooval\r\n";
23 is(scalar <$sock>, "STORED\r\n", "stored foo");
24
25 mem_get_is($sock, "foo", "fooval");
26 print $sock "flush_all 0\r\n";
27 is(scalar <$sock>, "OK\r\n", "did flush_all");
28 mem_get_is($sock, "foo", undef);
29
30 # check that flush_all doesn't blow away items that immediately get set
31 print $sock "set foo 0 0 3\r\nnew\r\n";
32 is(scalar <$sock>, "STORED\r\n", "stored foo = 'new'");
33 mem_get_is($sock, "foo", 'new');
34
35 # and the other form, specifying a flush_all time...
36 my $expire = time() + 2;
37 print $sock "flush_all $expire\r\n";
38 is(scalar <$sock>, "OK\r\n", "did flush_all in future");
39
40 print $sock "set foo 0 0 4\r\n1234\r\n";
41 is(scalar <$sock>, "STORED\r\n", "stored foo = '1234'");
42 mem_get_is($sock, "foo", '1234');
43 sleep(5);
44 mem_get_is($sock, "foo", undef);
45
46 print $sock "set foo 0 0 5\r\n12345\r\n";
47 is(scalar <$sock>, "STORED\r\n", "stored foo = '12345'");
48 mem_get_is($sock, "foo", '12345');
49 print $sock "flush_all 86400\r\n";
50 is(scalar <$sock>, "OK\r\n", "did flush_all for far future");
51 # Check foo still exists.
52 mem_get_is($sock, "foo", '12345');
53 print $sock "set foo2 0 0 5\r\n54321\r\n";
54 is(scalar <$sock>, "STORED\r\n", "stored foo2 = '54321'");
55 mem_get_is($sock, "foo", '12345');
56 mem_get_is($sock, "foo2", '54321');
57
58 # Test invalid argument
59 print $sock "flush_all invalid\r\n";
60 is(scalar <$sock>, "CLIENT_ERROR invalid exptime argument\r\n");
61
62 # Test -F option which disables flush_all
63 $server = new_memcached('-F');
64 $sock = $server->sock;
65
66 print $sock "set foo 0 0 7\r\nfooval2\r\n";
67 is(scalar <$sock>, "STORED\r\n", "stored foo");
68
69 mem_get_is($sock, "foo", "fooval2");
70 print $sock "flush_all\r\n";
71 is(scalar <$sock>, "CLIENT_ERROR flush_all not allowed\r\n", "flush_all was not allowed");
72 mem_get_is($sock, "foo", "fooval2");
73
74 # Test that disabling CAS makes flush_all less accurate.
75 # Due to lock ordering issues we can no longer evict items newer than
76 # oldest_live, so we rely on the CAS counter for an exact cliff. So disabling
77 # CAS now means all items set in the same second will fail to set.
78 $server = new_memcached('-C');
79 $sock = $server->sock;
80
81 my $failed_nocas = 0;
82 # Running this 100,000 times failed the test a handful of times. 50 tries
83 # should be enough.
84 for (1..50) {
85 print $sock "flush_all 0\r\n";
86 my $foo = scalar <$sock>;
87 print $sock "set foo 0 0 3\r\nnew\r\n";
88 $foo = scalar <$sock>;
89 print $sock "get foo\r\n";
90 my $line = scalar <$sock>;
91 if ($line =~ /^VALUE/) {
92 $line = scalar <$sock>;
93 $line = scalar <$sock>;
94 print STDERR "Succeeded!!!\n";
95 next;
96 } elsif ($line =~ /^END/) {
97 $failed_nocas++;
98 last;
99 }
100 }
101 is($failed_nocas, 1, "failed to set value after flush with no CAS at least once");