add tests for connection stats
@@ -23,8 +23,31 @@ EOT
my $port = $server->{port};
- # establish connections to the maximum (and write partial requests so that the server would accept(2) the connections)
+subtest 'the stats of active and inactive connections in HTTP/1.1' => sub {
my @conns;
+
+ # establish connections to the half of the maximum
+ for (1..3) {
+ my $conn = IO::Socket::INET->new(
+ PeerAddr => "127.0.0.1:$port",
+ Proto => "tcp",
+ ) or die "connection failed:$!";
+ push @conns, $conn;
+ }
+
+ sleep(2);
+
+ my $resp = `curl --silent -o /dev/stderr http://127.0.0.1:$server->{port}/s/json 2>&1 > /dev/null`;
+ my $jresp = decode_json("$resp");
+ is $jresp->{'connections'}, 4, 'connections';
+ is $jresp->{'active-connections'}, 1, 'active-connections';
+ is $jresp->{'inactive-connections'}, 3, 'inactive-connections';
+};
+
+subtest 'connection cluing' => sub {
+ my @conns;
+
+ # establish connections to the maximum (and write partial requests so that the server would accept(2) the connections)
for (1..10) {
my $conn = IO::Socket::INET->new(
PeerAddr => "127.0.0.1:$port",
@@ -52,9 +75,7 @@ EOT
$resp = `curl --silent -o /dev/stderr http://127.0.0.1:$server->{port}/s/json 2>&1 > /dev/null`;
$jresp = decode_json("$resp");
is $jresp->{'connections'}, 5, "Five connections";
+};
-
- while (@conns) {
- close shift @conns;
- }
+undef $server;
done_testing;
