"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/maxconns.t" (21 Feb 2022, 1516 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. See also the last Fossies "Diffs" side-by-side code changes report for "maxconns.t": 1.6.13_vs_1.6.14.

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