Mercurial > hg > nginx-tests
annotate grpc_ssl.t @ 1905:f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
The parse_stream() routine has had a missing explicit return if there were no
streams received. In Perl < 5.24 this used to return no value, or an empty
array in the list context. In modern Perl this returns an empty value, or an
array of 1 element, which made the check for last index of the returned array
work rather by accident.
The fix is to return explicitly and to check the array size in callers instead.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 06 Jun 2023 18:50:07 +0400 |
parents | 236d038dc04a |
children | b5036a0f9ae0 |
rev | line source |
---|---|
1303 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for grpc backend with ssl. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1312
6f95c0ed2335
Tests: removed proxy prerequisite from grpc tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1303
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) |
1860
58951cf933e1
Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1748
diff
changeset
|
27 ->has(qw/upstream_keepalive http_ssl openssl:1.0.2/) |
58951cf933e1
Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1748
diff
changeset
|
28 ->has_daemon('openssl') |
58951cf933e1
Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1748
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF')->plan(38); |
1303 | 30 |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 upstream u { | |
42 server 127.0.0.1:8081; | |
43 keepalive 1; | |
44 } | |
45 | |
46 server { | |
47 listen 127.0.0.1:8081 http2 ssl; | |
48 server_name localhost; | |
49 | |
50 ssl_certificate_key localhost.key; | |
51 ssl_certificate localhost.crt; | |
52 | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
53 ssl_verify_client optional; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
54 ssl_client_certificate client.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
55 |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
56 http2_body_preread_size 128k; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
57 |
1303 | 58 location / { |
59 grpc_pass 127.0.0.1:8082; | |
60 add_header X-Connection $connection; | |
61 } | |
62 } | |
63 | |
64 server { | |
65 listen 127.0.0.1:8080 http2; | |
66 server_name localhost; | |
67 | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
68 http2_body_preread_size 128k; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
69 |
1303 | 70 location / { |
71 grpc_pass grpcs://127.0.0.1:8081; | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
72 grpc_ssl_name localhost; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
73 grpc_ssl_verify on; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
74 grpc_ssl_trusted_certificate localhost.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
75 |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
76 grpc_ssl_certificate client.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
77 grpc_ssl_certificate_key client.key; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
78 grpc_ssl_password_file password; |
1303 | 79 |
80 if ($arg_if) { | |
81 # nothing | |
82 } | |
83 | |
84 limit_except GET { | |
85 # nothing | |
86 } | |
87 } | |
88 | |
89 location /KeepAlive { | |
90 grpc_pass grpcs://u; | |
91 } | |
92 } | |
93 } | |
94 | |
95 EOF | |
96 | |
97 $t->write_file('openssl.conf', <<EOF); | |
98 [ req ] | |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1415
diff
changeset
|
99 default_bits = 2048 |
1303 | 100 encrypt_key = no |
101 distinguished_name = req_distinguished_name | |
102 [ req_distinguished_name ] | |
103 EOF | |
104 | |
105 my $d = $t->testdir(); | |
106 | |
107 foreach my $name ('localhost') { | |
108 system('openssl req -x509 -new ' | |
109 . "-config $d/openssl.conf -subj /CN=$name/ " | |
110 . "-out $d/$name.crt -keyout $d/$name.key " | |
111 . ">>$d/openssl.out 2>&1") == 0 | |
112 or die "Can't create certificate for $name: $!\n"; | |
113 } | |
114 | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
115 foreach my $name ('client') { |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
116 system("openssl genrsa -out $d/$name.key -passout pass:$name " |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1415
diff
changeset
|
117 . "-aes128 2048 >>$d/openssl.out 2>&1") == 0 |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
118 or die "Can't create private key: $!\n"; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
119 system('openssl req -x509 -new ' |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
120 . "-config $d/openssl.conf -subj /CN=$name/ " |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
121 . "-out $d/$name.crt " |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
122 . "-key $d/$name.key -passin pass:$name" |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
123 . ">>$d/openssl.out 2>&1") == 0 |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
124 or die "Can't create certificate for $name: $!\n"; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
125 } |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
126 |
1323
6eb3dd2d4d5a
Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
127 sleep 1 if $^O eq 'MSWin32'; |
6eb3dd2d4d5a
Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
128 |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
129 $t->write_file('password', 'client'); |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
130 |
1900
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1860
diff
changeset
|
131 # suppress deprecation warning |
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1860
diff
changeset
|
132 |
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1860
diff
changeset
|
133 open OLDERR, ">&", \*STDERR; close STDERR; |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1378
diff
changeset
|
134 $t->run(); |
1900
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1860
diff
changeset
|
135 open STDERR, ">&", \*OLDERR; |
1303 | 136 |
137 ############################################################################### | |
138 | |
139 my $p = port(8082); | |
140 my $f = grpc(); | |
141 | |
142 my $frames = $f->{http_start}('/SayHello'); | |
143 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
144 is($frame->{flags}, 4, 'request - HEADERS flags'); | |
145 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd'); | |
146 is($frame->{headers}{':method'}, 'POST', 'request - method'); | |
147 is($frame->{headers}{':scheme'}, 'http', 'request - scheme'); | |
148 is($frame->{headers}{':path'}, '/SayHello', 'request - path'); | |
149 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority'); | |
150 is($frame->{headers}{'content-type'}, 'application/grpc', | |
151 'request - content type'); | |
152 is($frame->{headers}{te}, 'trailers', 'request - te'); | |
153 | |
154 $frames = $f->{data}('Hello'); | |
155 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames; | |
156 is($frame->{flags}, 1, 'request - SETTINGS ack'); | |
157 is($frame->{sid}, 0, 'request - SETTINGS sid'); | |
158 is($frame->{length}, 0, 'request - SETTINGS length'); | |
159 | |
160 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
161 is($frame->{data}, 'Hello', 'request - DATA'); | |
162 is($frame->{length}, 5, 'request - DATA length'); | |
163 is($frame->{flags}, 1, 'request - DATA flags'); | |
164 is($frame->{sid}, $sid, 'request - DATA sid match'); | |
165 | |
166 $frames = $f->{http_end}(); | |
167 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
168 is($frame->{flags}, 4, 'response - HEADERS flags'); | |
169 is($frame->{sid}, 1, 'response - HEADERS sid'); | |
170 is($frame->{headers}{':status'}, '200', 'response - status'); | |
171 is($frame->{headers}{'content-type'}, 'application/grpc', | |
172 'response - content type'); | |
173 ok($frame->{headers}{server}, 'response - server'); | |
174 ok($frame->{headers}{date}, 'response - date'); | |
175 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection'); | |
176 | |
177 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
178 is($frame->{data}, 'Hello world', 'response - DATA'); | |
179 is($frame->{length}, 11, 'response - DATA length'); | |
180 is($frame->{flags}, 0, 'response - DATA flags'); | |
181 is($frame->{sid}, 1, 'response - DATA sid'); | |
182 | |
183 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
184 is($frame->{flags}, 5, 'response - trailers flags'); | |
185 is($frame->{sid}, 1, 'response - trailers sid'); | |
186 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message'); | |
187 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status'); | |
188 | |
189 # next request is on a new backend connection, no sid incremented | |
190 | |
191 $f->{http_start}('/SayHello'); | |
192 $f->{data}('Hello'); | |
193 $frames = $f->{http_end}(); | |
194 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
195 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection'); | |
196 | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
197 # flow control |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
198 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
199 $f->{http_start}('/FlowControl'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
200 $frames = $f->{data_len}(('Hello' x 13000) . ('x' x 550), 65535); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
201 my $sum = eval join '+', map { $_->{type} eq "DATA" && $_->{length} } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
202 is($sum, 65535, 'flow control - iws length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
203 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
204 $f->{update}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
205 $f->{update_sid}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
206 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
207 $frames = $f->{data_len}(undef, 10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
208 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
209 is($frame->{length}, 10, 'flow control - update length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
210 is($frame->{flags}, 0, 'flow control - update flags'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
211 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
212 $f->{update_sid}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
213 $f->{update}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
214 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
215 $frames = $f->{data_len}(undef, 5); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
216 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
217 is($frame->{length}, 5, 'flow control - rest length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
218 is($frame->{flags}, 1, 'flow control - rest flags'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
219 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
220 $f->{http_end}(); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
221 |
1303 | 222 # upstream keepalive |
223 | |
224 $f->{http_start}('/KeepAlive'); | |
225 $f->{data}('Hello'); | |
226 $frames = $f->{http_end}(); | |
227 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
228 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection'); | |
229 | |
230 $f->{http_start}('/KeepAlive'); | |
231 $f->{data}('Hello'); | |
232 $frames = $f->{http_end}(); | |
233 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
234 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse'); | |
235 | |
236 ############################################################################### | |
237 | |
238 sub grpc { | |
239 my ($server, $client, $f, $s, $c, $sid, $uri); | |
240 | |
241 $server = IO::Socket::INET->new( | |
242 Proto => 'tcp', | |
243 LocalHost => '127.0.0.1', | |
244 LocalPort => $p, | |
245 Listen => 5, | |
246 Reuse => 1 | |
247 ) | |
248 or die "Can't create listening socket: $!\n"; | |
249 | |
250 $f->{http_start} = sub { | |
251 ($uri, my %extra) = @_; | |
252 my $body_more = 1 if $uri !~ /LongHeader/; | |
253 $s = Test::Nginx::HTTP2->new() if !defined $s; | |
254 $s->new_stream({ body_more => $body_more, headers => [ | |
255 { name => ':method', value => 'POST', mode => 0 }, | |
256 { name => ':scheme', value => 'http', mode => 0 }, | |
257 { name => ':path', value => $uri, }, | |
258 { name => ':authority', value => 'localhost' }, | |
259 { name => 'content-type', value => 'application/grpc' }, | |
260 { name => 'te', value => 'trailers', mode => 2 }]}); | |
261 | |
262 if (!$extra{reuse}) { | |
1321
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
263 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
264 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:
1313
diff
changeset
|
265 alarm(5); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
266 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
267 $client = $server->accept() or return; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
268 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
269 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
270 }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
271 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
272 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
273 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
274 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
275 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
276 |
1303 | 277 log2c("(new connection $client)"); |
278 | |
279 $client->sysread(my $buf, 24) == 24 or return; # preface | |
280 | |
281 $c = Test::Nginx::HTTP2->new(1, socket => $client, | |
282 pure => 1, preface => "") or return; | |
283 } | |
284 | |
285 my $frames = $c->read(all => [{ fin => 4 }]); | |
286 | |
287 if (!$extra{reuse}) { | |
288 $c->h2_settings(0); | |
289 $c->h2_settings(1); | |
290 } | |
291 | |
292 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
293 $sid = $frame->{sid}; | |
294 return $frames; | |
295 }; | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
296 $f->{data_len} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
297 my ($body, $len) = @_; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
298 $s->h2_body($body) if defined $body; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
299 return $c->read(all => [{ sid => $sid, length => $len }]); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
300 }; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
301 $f->{update} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
302 $c->h2_window(shift); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
303 }; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
304 $f->{update_sid} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
305 $c->h2_window(shift, $sid); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
306 }; |
1303 | 307 $f->{data} = sub { |
308 my ($body, %extra) = @_; | |
309 $s->h2_body($body, { %extra }); | |
310 return $c->read(all => [{ sid => $sid, | |
311 length => length($body) }]); | |
312 }; | |
313 $f->{http_end} = sub { | |
314 $c->new_stream({ body_more => 1, headers => [ | |
315 { name => ':status', value => '200', mode => 0 }, | |
316 { name => 'content-type', value => 'application/grpc', | |
317 mode => 1, huff => 1 }, | |
318 ]}, $sid); | |
319 $c->h2_body('Hello world', { body_more => 1 }); | |
320 $c->new_stream({ headers => [ | |
321 { name => 'grpc-status', value => '0', | |
322 mode => 2, huff => 1 }, | |
323 { name => 'grpc-message', value => '', | |
324 mode => 2, huff => 1 }, | |
325 ]}, $sid); | |
326 | |
327 return $s->read(all => [{ fin => 1 }]); | |
328 }; | |
329 return $f; | |
330 } | |
331 | |
332 sub log2i { Test::Nginx::log_core('|| <<', @_); } | |
333 sub log2o { Test::Nginx::log_core('|| >>', @_); } | |
334 sub log2c { Test::Nginx::log_core('||', @_); } | |
335 | |
336 ############################################################################### |