# HG changeset patch # User Sergey Kandaurov # Date 1617875951 -10800 # Node ID bdebd63dbab37144f8b13a1a67a14c7bff161d93 # Parent 9d4c88e5c18310749a6861a5f7dc62729fd6f189 Tests: keepalive_time tests. diff --git a/h2_max_requests.t b/h2_max_requests.t --- a/h2_max_requests.t +++ b/h2_max_requests.t @@ -56,6 +56,15 @@ http { location / { } } + + server { + listen 127.0.0.1:8082 http2; + server_name localhost; + + keepalive_time 1s; + + location / { } + } } EOF @@ -66,7 +75,7 @@ EOF # suppress deprecation warning open OLDERR, ">&", \*STDERR; close STDERR; -$t->run()->plan(12); +$t->try_run('no keepalive_time')->plan(17); open STDERR, ">&", \*OLDERR; ############################################################################### @@ -141,6 +150,32 @@ ok($frame, 'keepalive_timeout 0 - GOAWAY } +# keepalive_time + +$s = Test::Nginx::HTTP2->new(port(8082)); +$sid = $s->new_stream({ path => '/t.html' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "HEADERS" } @$frames; +is($frame->{headers}->{':status'}, 200, 'keepalive time request'); + +$frames = $s->read(all => [{ type => 'GOAWAY' }], wait => 0.5); + +($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; +is($frame, undef, 'keepalive time - no GOAWAY yet'); + +select undef, undef, undef, 1.1; + +$sid = $s->new_stream({ path => '/t.html' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); + +($frame) = grep { $_->{type} eq "HEADERS" } @$frames; +is($frame->{headers}->{':status'}, 200, 'keepalive time request 2'); + +($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; +ok($frame, 'keepalive time limit - GOAWAY'); +is($frame->{last_sid}, $sid, 'keepalive time limit - GOAWAY last stream'); + # graceful shutdown in idle state $s = Test::Nginx::HTTP2->new(); diff --git a/http_keepalive.t b/http_keepalive.t --- a/http_keepalive.t +++ b/http_keepalive.t @@ -24,7 +24,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http/)->plan(16) +my $t = Test::Nginx->new()->has(qw/http/) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -55,6 +55,12 @@ http { keepalive_timeout 30s; } + location /time { + keepalive_requests 100; + keepalive_timeout 75s; + keepalive_time 1s; + } + location /safari { keepalive_disable safari; } @@ -73,10 +79,11 @@ EOF $t->write_file('index.html', ''); $t->write_file('r', ''); +$t->write_file('time', ''); $t->write_file('safari', ''); $t->write_file('none', ''); $t->write_file('zero', ''); -$t->run(); +$t->try_run('no keepalive_time')->plan(20); ############################################################################### @@ -110,6 +117,16 @@ like($r, qr/Keep-Alive: timeout=9/, 'kee like(http_keepalive('/zero'), qr/Connection: close/, 'keepalive timeout 0'); +# keepalive_time + +$r = http_keepalive('/time', req => 3); +is(() = $r =~ /(200 OK)/g, 3, 'keepalive time requests'); +unlike($r, qr/Connection: close/, 'keepalive time connection'); + +$r = http_keepalive('/time', req => 3, sleep => 1.1); +is(() = $r =~ /(200 OK)/g, 2, 'keepalive time limit requests'); +like($r, qr/Connection: close/, 'keepalive time limit connection'); + # cancel keepalive on EOF while discarding body my $s = http(< 1);