1#!/usr/bin/perl 2# Networked logging tests. 3 4use strict; 5use warnings; 6use Socket qw/SO_RCVBUF/; 7 8use Test::More tests => 8; 9use FindBin qw($Bin); 10use lib "$Bin/lib"; 11use MemcachedTest; 12 13my $server = new_memcached('-m 60 -o watcher_logbuf_size=8'); 14my $client = $server->sock; 15my $watcher = $server->new_sock; 16 17# This doesn't return anything. 18print $watcher "watch\n"; 19my $res = <$watcher>; 20is($res, "OK\r\n", "watcher enabled"); 21 22print $client "get foo\n"; 23$res = <$client>; 24is($res, "END\r\n", "basic get works"); 25my $spacer = "X"x180; 26 27# This is a flaky test... depends on buffer sizes. Could either have memc 28# shrink the watcher buffer, or loop this and keep doubling until we get some 29# skipped values. 30for (1 .. 80000) { 31 print $client "get foo$_$spacer\n"; 32 $res = <$client>; 33} 34 35# Let the logger thread catch up before we start reading. 36sleep 1; 37my $do_fetch = 0; 38#print STDERR "RESULT: $res\n"; 39while (my $log = <$watcher>) { 40 # The "skipped" line won't actually print until some space frees up in the 41 # buffer, so we need to occasionally cause new lines to generate. 42 if (($do_fetch++ % 100) == 0) { 43 print $client "get foo\n"; 44 $res = <$client>; 45 } 46 next unless $log =~ m/skipped/; 47 like($log, qr/skipped=/, "skipped some lines"); 48 # This should unjam more of the text. 49 print $client "get foob\n"; 50 $res = <$client>; 51 last; 52} 53$res = <$watcher>; 54like($res, qr/ts=\d+\.\d+\ gid=\d+ type=item_get/, "saw a real log line after a skip"); 55 56# test combined logs 57# fill to evictions, then enable watcher, set again, and look for both lines 58 59{ 60 my $value = "B"x11000; 61 my $keycount = 8000; 62 63 for (1 .. $keycount) { 64 print $client "set n,foo$_ 0 0 11000 noreply\r\n$value\r\n"; 65 } 66 67 $watcher = $server->new_sock; 68 print $watcher "watch mutations evictions\n"; 69 $res = <$watcher>; 70 is($res, "OK\r\n", "new watcher enabled"); 71 my $watcher2 = $server->new_sock; 72 print $watcher2 "watch evictions\n"; 73 $res = <$watcher2>; 74 is($res, "OK\r\n", "evictions watcher enabled"); 75 76 print $client "set bfoo 0 0 11000 noreply\r\n$value\r\n"; 77 my $found_log = 0; 78 my $found_ev = 0; 79 while (my $log = <$watcher>) { 80 $found_log = 1 if ($log =~ m/type=item_store/); 81 $found_ev = 1 if ($log =~ m/type=eviction/); 82 last if ($found_log && $found_ev); 83 } 84 is($found_log, 1, "found rawcmd log entry"); 85 is($found_ev, 1, "found eviction log entry"); 86} 87