"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/watcher_connid.t" (21 Feb 2022, 2045 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 # Test for adding connection id to the output when watching fetchers
3 # and mutations.
4 # Note that this test relies on the order of connection establishments. This
5 # could be improved if there's a way for a client to retrieve its connection id.
6 use strict;
7 use warnings;
8 use Socket qw/SO_RCVBUF/;
9
10 use Test::More tests => 4;
11 use FindBin qw($Bin);
12 use lib "$Bin/lib";
13 use MemcachedTest;
14
15 my $server = new_memcached('-m 60 -o watcher_logbuf_size=8');
16 my $client_first = $server->sock;
17
18 my $stats;
19
20 # get the first client's connection id
21 print $client_first "stats conns\r\n";
22 while (<$client_first>) {
23 last if /^(\.|END)/;
24 $stats = $_;
25 }
26 my $cfd_first =(split(':', $stats))[0];
27 $cfd_first =~ s/[^0-9]//g;
28
29 # start watching fetchers and mutations
30 my $watcher = $server->new_sock;
31 print $watcher "watch fetchers mutations\n";
32 my $res = <$watcher>;
33 is($res, "OK\r\n", "watching enabled for fetchers and mutations");
34
35 # first client does a set, which will result in a get and a set
36 print $client_first "set foo 0 0 5 noreply\r\nhello\r\n";
37
38 # ensure client's connection id is correct
39 $res = <$watcher>;
40 print $res;
41 like($res, qr/ts=\d+\.\d+\ gid=\d+ type=item_get key=foo status=not_found clsid=\d+ cfd=$cfd_first/,
42 "Saw a miss with the connection id $cfd_first");
43 $res = <$watcher>;
44 print $res;
45 like($res, qr/ts=\d+\.\d+\ gid=\d+ type=item_store key=foo status=stored cmd=set ttl=\d+ clsid=\d+ cfd=$cfd_first/,
46 "Saw a set with the connection id $cfd_first");
47
48 # get the second client's connection id
49 my $client_second = $server->new_sock;
50 print $client_second "stats conns\r\n";
51 while (<$client_second>) {
52 last if /^(\.|END)/;
53 $stats = $_;
54 }
55 my $cfd_second =(split(':', $stats))[0];
56 $cfd_second =~ s/[^0-9]//g;
57
58 # second client does a get
59 print $client_second "get foo\r\n";
60
61 # now we should see second client's connection id
62 $res = <$watcher>;
63 print $res;
64 like($res, qr/ts=\d+\.\d+\ gid=\d+ type=item_get key=foo status=found clsid=\d+ cfd=$cfd_second/,
65 "Saw a get with the connection id $cfd_second");
66