Mercurial > hg > nginx-tests
changeset 1667:bdebd63dbab3
Tests: keepalive_time tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 08 Apr 2021 12:59:11 +0300 |
parents | 9d4c88e5c183 |
children | 0c1bd4c23c95 |
files | h2_max_requests.t http_keepalive.t |
diffstat | 2 files changed, 55 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/h2_max_requests.t Sat Mar 27 16:18:56 2021 +0000 +++ b/h2_max_requests.t Thu Apr 08 12:59:11 2021 +0300 @@ -56,6 +56,15 @@ location / { } } + + server { + listen 127.0.0.1:8082 http2; + server_name localhost; + + keepalive_time 1s; + + location / { } + } } EOF @@ -66,7 +75,7 @@ # 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 @@ } +# 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();
--- a/http_keepalive.t Sat Mar 27 16:18:56 2021 +0000 +++ b/http_keepalive.t Thu Apr 08 12:59:11 2021 +0300 @@ -24,7 +24,7 @@ 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 @@ keepalive_timeout 30s; } + location /time { + keepalive_requests 100; + keepalive_timeout 75s; + keepalive_time 1s; + } + location /safari { keepalive_disable safari; } @@ -73,10 +79,11 @@ $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(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(<<EOF, start => 1);