summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorKevin Lin <developer@kevinlin.info>2021-05-29 22:19:43 -0700
committerdormando <dormando@rydia.net>2021-08-07 01:16:14 -0700
commit617d7cd64d04698b76fee74882627690017e20ad (patch)
treede5c4b129c419ba32e1a403d58871bd0f05da25d /t
parenta54f34f34c3ddef3f6e13f62f3ab673f681cac95 (diff)
downloadmemcached-617d7cd64d04698b76fee74882627690017e20ad.tar.gz
Implement LOG_CONNEVENTS watcher flag for connection state transitions
Add support for `watch connevents` to report opened (`conn_new`) and closed (`conn_close`) client connections. Event log lines indicate the connection's remote IP, remote port, and transport type. `conn_close` events additionally supply a reason for the closing the connection.
Diffstat (limited to 't')
-rw-r--r--t/watcher.t36
1 files changed, 35 insertions, 1 deletions
diff --git a/t/watcher.t b/t/watcher.t
index 43dd7a6..c624fb9 100644
--- a/t/watcher.t
+++ b/t/watcher.t
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Socket qw/SO_RCVBUF/;
-use Test::More tests => 20;
+use Test::More tests => 25;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
@@ -72,6 +72,40 @@ if ($res eq "STORED\r\n") {
}
}
+# test connection events
+{
+ # start a dedicated server so that connection close events from previous
+ # tests don't leak into this one due to races.
+ my $conn_server = new_memcached('-m 60 -o watcher_logbuf_size=8');
+ my $conn_watcher = $conn_server->new_sock;
+
+ print $conn_watcher "watch connevents\n";
+ $res = <$conn_watcher>;
+ is($res, "OK\r\n", 'connevents watcher enabled');
+
+ # normal close
+ my $conn_client = $conn_server->new_sock;
+ print $conn_client "version\r\n";
+ $res = <$conn_client>;
+ print $conn_client "quit\r\n";
+ $res = <$conn_watcher>;
+ like($res, qr/ts=\d+\.\d+\ gid=\d+ type=conn_new .+ transport=local/,
+ 'logged new connection');
+ $res = <$conn_watcher>;
+ like($res, qr/ts=\d+\.\d+\ gid=\d+ type=conn_close .+ transport=local reason=normal/,
+ 'logged closed connection due to client disconnect');
+
+ # error close
+ $conn_client = $conn_server->new_sock;
+ print $conn_client "GET / HTTP/1.1\r\n";
+ $res = <$conn_watcher>;
+ like($res, qr/ts=\d+\.\d+\ gid=\d+ type=conn_new .+ transport=local/,
+ 'logged new connection');
+ $res = <$conn_watcher>;
+ like($res, qr/ts=\d+\.\d+\ gid=\d+ type=conn_close .+ transport=local reason=error/,
+ 'logged closed connection due to client protocol error');
+}
+
# test combined logs
# fill to evictions, then enable watcher, set again, and look for both lines