annotate grpc_request_buffering.t @ 1940:aec72dcee93b

Tests: unconditional QUIC datagram expansion with Initial packets. Used to get rid of "quic UDP datagram is too small for initial packet" messages. In future, we may need this to reconsider to allow mocking with custom padding, but for now suppressing such messages is sufficiently good enough.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 11 Dec 2023 14:01:49 +0400
parents 236d038dc04a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for grpc module, request body buffered.
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP2;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
1381
97c8280de681 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1356
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http http_v2 grpc mirror proxy/)->plan(12);
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 $t->write_file_expand('nginx.conf', <<'EOF');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 daemon off;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 events {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 http {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 %%TEST_GLOBALS_HTTP%%
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 listen 127.0.0.1:8080 http2;
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
42 listen 127.0.0.1:8082;
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server_name localhost;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location /mirror { }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 location / {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 grpc_pass 127.0.0.1:8081;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 add_header X-Body $request_body;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 mirror /mirror;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
52
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
53 location /proxy {
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
54 proxy_pass http://127.0.0.1:8082/mirror;
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
55 proxy_intercept_errors on;
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
56 error_page 404 = @fallback;
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
57 }
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
58
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
59 location @fallback {
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
60 grpc_pass 127.0.0.1:8081;
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
61 }
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 EOF
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1415
diff changeset
67 # suppress deprecation warning
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1415
diff changeset
68
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1415
diff changeset
69 open OLDERR, ">&", \*STDERR; close STDERR;
1381
97c8280de681 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1356
diff changeset
70 $t->run();
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1415
diff changeset
71 open STDERR, ">&", \*OLDERR;
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 ###############################################################################
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 my $p = port(8081);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 my $f = grpc();
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 my $frames = $f->{http_start}('/SayHello');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 is($frame->{flags}, 4, 'request - HEADERS flags');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 is($frame->{headers}{':method'}, 'POST', 'request - method');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 is($frame->{headers}{':scheme'}, 'http', 'request - scheme');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 is($frame->{headers}{':path'}, '/SayHello', 'request - path');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 is($frame->{data}, 'Hello', 'request - DATA');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 is($frame->{length}, 5, 'request - DATA length');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 is($frame->{flags}, 1, 'request - DATA flags');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 $frames = $f->{http_end}();
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 is($frame->{headers}{'x-body'}, 'Hello', 'request body in memory');
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
1356
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
95 # tcp_nopush usage on peer connections
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
96 # reopen window for request body after initial window was exhausted
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
97
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
98 $frames = $f->{http_start}('/proxy');
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
99 is(eval(join '+', map { $_->{length} } grep { $_->{type} eq "DATA" } @$frames),
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
100 65535, 'preserve_output - first body bytes');
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
101
1356
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
102 # expect body cleanup is disabled with preserve_output (ticket #1565).
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
103 # after request body first bytes were proxied on behalf of initial window size,
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
104 # send response header from upstream, this leads to body cleanup code path
ca6fe31f74c4 Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1353
diff changeset
105
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
106 $frames = $f->{http_end}();
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
107 is(eval(join '+', map { $_->{length} } grep { $_->{type} eq "DATA" } @$frames),
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
108 465, 'preserve_output - last body bytes');
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
109
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
110 like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crits');
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
111
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 ###############################################################################
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 sub grpc {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 my ($server, $client, $f, $s, $c, $sid, $uri);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 $server = IO::Socket::INET->new(
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 Proto => 'tcp',
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 LocalHost => '127.0.0.1',
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 LocalPort => $p,
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 Listen => 5,
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 Reuse => 1
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 )
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 or die "Can't create listening socket: $!\n";
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 $f->{http_start} = sub {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 ($uri, my %extra) = @_;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 $s = Test::Nginx::HTTP2->new() if !defined $s;
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
129 my ($body) = $uri eq '/proxy' ? 'Hello' x 13200 : 'Hello';
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
130 $s->new_stream({ body => $body, headers => [
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 { name => ':method', value => 'POST', mode => 0 },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 { name => ':scheme', value => 'http', mode => 0 },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 { name => ':path', value => $uri },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 { name => ':authority', value => 'localhost' },
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
135 { name => 'content-length', value => length($body) }]});
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 if (!$extra{reuse}) {
1321
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
138 eval {
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
139 local $SIG{ALRM} = sub { die "timeout\n" };
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
140 alarm(5);
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
141
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
142 $client = $server->accept() or return;
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
143
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
144 alarm(0);
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
145 };
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
146 alarm(0);
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
147 if ($@) {
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
148 log_in("died: $@");
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
149 return undef;
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
150 }
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1311
diff changeset
151
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 log2c("(new connection $client)");
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 $client->sysread(my $buf, 24) == 24 or return; # preface
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 $c = Test::Nginx::HTTP2->new(1, socket => $client,
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 pure => 1, preface => "") or return;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
160 my $frames = $uri eq '/proxy'
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
161 ? $c->read(all => [{ length => 65535 }])
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
162 : $c->read(all => [{ fin => 1 }]);
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 if (!$extra{reuse}) {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 $c->h2_settings(0);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 $c->h2_settings(1);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 $sid = $frame->{sid};
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 return $frames;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 };
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 $f->{http_end} = sub {
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 $c->new_stream({ body_more => 1, headers => [
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 { name => ':status', value => '200', mode => 0 },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 { name => 'content-type', value => 'application/grpc' },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 ]}, $sid);
1353
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
178
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
179 # reopen window for request body after response HEADERS is sent
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
180
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
181 if ($uri eq '/proxy') {
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
182 $c->h2_window(2**16, $sid);
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
183 $c->h2_window(2**16);
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
184 return $c->read(all => [{ sid => $sid, fin => 1 }]);
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
185 }
65730ba03b42 Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
186
1311
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 $c->h2_body('Hello world', { body_more => 1 });
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 $c->new_stream({ headers => [
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 { name => 'grpc-status', value => '0', mode => 2 },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 { name => 'grpc-message', value => '', mode => 2 },
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 ]}, $sid);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 return $s->read(all => [{ fin => 1 }]);
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 };
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 return $f;
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 sub log2c { Test::Nginx::log_core('||', @_); }
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199
4979af9fd905 Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 ###############################################################################