Mercurial > hg > nginx-tests
annotate grpc_request_buffering.t @ 1435:cace66c3ce56
Tests: removed js tests for deprecated njs API.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 28 Jan 2019 16:17:11 +0300 |
parents | 01d806268a12 |
children | 236d038dc04a |
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 |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1356
diff
changeset
|
67 $t->run(); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $p = port(8081); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my $f = grpc(); |
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 my $frames = $f->{http_start}('/SayHello'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 is($frame->{flags}, 4, 'request - HEADERS flags'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 is($frame->{headers}{':method'}, 'POST', 'request - method'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 is($frame->{headers}{':scheme'}, 'http', 'request - scheme'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 is($frame->{headers}{':path'}, '/SayHello', 'request - path'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 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
|
81 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 is($frame->{data}, 'Hello', 'request - DATA'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 is($frame->{length}, 5, 'request - DATA length'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 is($frame->{flags}, 1, 'request - DATA flags'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $frames = $f->{http_end}(); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 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
|
90 |
1356
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
91 # 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
|
92 # 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
|
93 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
94 $frames = $f->{http_start}('/proxy'); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
95 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
|
96 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
|
97 |
1356
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
98 # 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
|
99 # 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
|
100 # 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
|
101 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
102 $frames = $f->{http_end}(); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
103 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
|
104 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
|
105 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
106 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
|
107 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 ############################################################################### |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 sub grpc { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 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
|
112 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 $server = IO::Socket::INET->new( |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 Proto => 'tcp', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 LocalHost => '127.0.0.1', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 LocalPort => $p, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 Listen => 5, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 Reuse => 1 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 ) |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 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
|
121 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 $f->{http_start} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 ($uri, my %extra) = @_; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $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
|
125 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
|
126 $s->new_stream({ body => $body, headers => [ |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 { name => ':method', value => 'POST', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 { name => ':scheme', value => 'http', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 { name => ':path', value => $uri }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 { name => ':authority', value => 'localhost' }, |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
131 { name => 'content-length', value => length($body) }]}); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 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
|
134 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
135 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
|
136 alarm(5); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
137 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
138 $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
|
139 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
140 alarm(0); |
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 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
143 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
144 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
145 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
146 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
147 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 log2c("(new connection $client)"); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 $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
|
151 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $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
|
153 pure => 1, preface => "") or return; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
156 my $frames = $uri eq '/proxy' |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
157 ? $c->read(all => [{ length => 65535 }]) |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
158 : $c->read(all => [{ fin => 1 }]); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 if (!$extra{reuse}) { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 $c->h2_settings(0); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 $c->h2_settings(1); |
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 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 $sid = $frame->{sid}; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 return $frames; |
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 $f->{http_end} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 $c->new_stream({ body_more => 1, headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 { name => ':status', value => '200', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 { name => 'content-type', value => 'application/grpc' }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 ]}, $sid); |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
174 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
175 # 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
|
176 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
177 if ($uri eq '/proxy') { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
178 $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
|
179 $c->h2_window(2**16); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
180 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
|
181 } |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
182 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 $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
|
184 $c->new_stream({ headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 { name => 'grpc-status', value => '0', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 { name => 'grpc-message', value => '', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 ]}, $sid); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 return $s->read(all => [{ fin => 1 }]); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 }; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 return $f; |
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 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 sub log2c { Test::Nginx::log_core('||', @_); } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 ############################################################################### |