1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
my $server = new_memcached();
test_maxconns($server);
my $ext_path;
if (supports_extstore()) {
$ext_path = "/tmp/extstore.$$";
my $server = new_memcached("-m 64 -U 0 -o ext_path=$ext_path:64m");
test_maxconns($server);
}
sub test_maxconns {
my $server = shift;
my $stat_sock = $server->sock;
my @sockets = ();
my $num_sockets;
my $rejected_conns = 0;
my $stats;
for (1 .. 1024) {
my $sock = $server->new_sock;
if (defined($sock)) {
push(@sockets, $sock);
$stats = mem_stats($stat_sock);
if ($stats->{rejected_connections} > $rejected_conns) {
$rejected_conns = $stats->{rejected_connections};
my $buffer = "";
my $length = 31;
my $res = recv($sock, $buffer, $length, 0);
if (not $buffer eq '') {
is($buffer, "ERROR Too many open connections", "Got expected response from the server");
}
}
}
}
my $failed = 1;
for (1 .. 5) {
$stats = mem_stats($stat_sock);
if ($stats->{rejected_connections} != 0) {
$failed = 0;
last;
}
sleep 1;
}
is($failed, 0, "rejected connections were observed.");
for my $s (@sockets) {
$s->close();
}
$server->stop;
$stat_sock->close();
}
done_testing();
END {
unlink $ext_path if $ext_path;
}
|