# HG changeset patch # User Sergey Kandaurov # Date 1530696293 -10800 # Node ID 65730ba03b42defc9da94fab5d2b1401ad26c5c3 # Parent 32156faf018e3b36f7661810cadf477904afe080 Tests: body cleanup test with preserve_output (ticket #1565). diff --git a/grpc_request_buffering.t b/grpc_request_buffering.t --- a/grpc_request_buffering.t +++ b/grpc_request_buffering.t @@ -23,7 +23,7 @@ use Test::Nginx::HTTP2; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http http_v2 grpc mirror/); +my $t = Test::Nginx->new()->has(qw/http http_v2 grpc mirror proxy/); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -39,6 +39,7 @@ http { server { listen 127.0.0.1:8080 http2; + listen 127.0.0.1:8082; server_name localhost; location /mirror { } @@ -48,12 +49,22 @@ http { add_header X-Body $request_body; mirror /mirror; } + + location /proxy { + proxy_pass http://127.0.0.1:8082/mirror; + proxy_intercept_errors on; + error_page 404 = @fallback; + } + + location @fallback { + grpc_pass 127.0.0.1:8081; + } } } EOF -$t->try_run('no grpc')->plan(9); +$t->try_run('no grpc')->plan(12); ############################################################################### @@ -77,6 +88,28 @@ is($frame->{flags}, 1, 'request - DATA f ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; is($frame->{headers}{'x-body'}, 'Hello', 'request body in memory'); +# expect body cleanup is disabled with preserve_output (ticket #1565). +# after request body first bytes were proxied on behalf of initial window size, +# send response header from upstream, this leads to body cleanup code path + +$frames = $f->{http_start}('/proxy'); +is(eval(join '+', map { $_->{length} } grep { $_->{type} eq "DATA" } @$frames), + 65535, 'preserve_output - first body bytes'); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.15.1'); + +$frames = $f->{http_end}(); +is(eval(join '+', map { $_->{length} } grep { $_->{type} eq "DATA" } @$frames), + 465, 'preserve_output - last body bytes'); + +like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crits'); + +} + +$t->todo_alerts() if $t->read_file('nginx.conf') =~ /sendfile on/ + and !$t->has_version('1.15.1'); + ############################################################################### sub grpc { @@ -94,12 +127,13 @@ sub grpc { $f->{http_start} = sub { ($uri, my %extra) = @_; $s = Test::Nginx::HTTP2->new() if !defined $s; - $s->new_stream({ body => 'Hello', headers => [ + my ($body) = $uri eq '/proxy' ? 'Hello' x 13200 : 'Hello'; + $s->new_stream({ body => $body, headers => [ { name => ':method', value => 'POST', mode => 0 }, { name => ':scheme', value => 'http', mode => 0 }, { name => ':path', value => $uri }, { name => ':authority', value => 'localhost' }, - { name => 'content-length', value => '5' }]}); + { name => 'content-length', value => length($body) }]}); if (!$extra{reuse}) { eval { @@ -124,7 +158,9 @@ sub grpc { pure => 1, preface => "") or return; } - my $frames = $c->read(all => [{ fin => 1 }]); + my $frames = $uri eq '/proxy' + ? $c->read(all => [{ length => 65535 }]) + : $c->read(all => [{ fin => 1 }]); if (!$extra{reuse}) { $c->h2_settings(0); @@ -140,6 +176,15 @@ sub grpc { { name => ':status', value => '200', mode => 0 }, { name => 'content-type', value => 'application/grpc' }, ]}, $sid); + + # reopen window for request body after response HEADERS is sent + + if ($uri eq '/proxy') { + $c->h2_window(2**16, $sid); + $c->h2_window(2**16); + return $c->read(all => [{ sid => $sid, fin => 1 }]); + } + $c->h2_body('Hello world', { body_more => 1 }); $c->new_stream({ headers => [ { name => 'grpc-status', value => '0', mode => 2 },