Mercurial > hg > nginx-tests
annotate grpc_request_buffering.t @ 1396:28ddfda3ca2a
Tests: stream tests for the proxy_requests directive.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 13 Nov 2018 13:20:25 +0300 |
parents | 97c8280de681 |
children | 01d806268a12 |
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 |
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
94 TODO: { |
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
95 local $TODO = 'not yet' if $t->read_file('nginx.conf') =~ /sendfile on/ |
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
96 and !$t->has_version('1.15.1') and $^O eq 'freebsd'; |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
97 |
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 } |
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
103 |
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
104 # 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
|
105 # 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
|
106 # 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
|
107 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
108 TODO: { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
109 local $TODO = 'not yet' unless $t->has_version('1.15.1'); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
110 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
111 $frames = $f->{http_end}(); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
112 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
|
113 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
|
114 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
115 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
|
116 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
117 } |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
118 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
119 $t->todo_alerts() if $t->read_file('nginx.conf') =~ /sendfile on/ |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
120 and !$t->has_version('1.15.1'); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
121 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 ############################################################################### |
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 sub grpc { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 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
|
126 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 $server = IO::Socket::INET->new( |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 Proto => 'tcp', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 LocalHost => '127.0.0.1', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 LocalPort => $p, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 Listen => 5, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 Reuse => 1 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 ) |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 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
|
135 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 $f->{http_start} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 ($uri, my %extra) = @_; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 $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
|
139 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
|
140 $s->new_stream({ body => $body, headers => [ |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 { name => ':method', value => 'POST', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 { name => ':scheme', value => 'http', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 { name => ':path', value => $uri }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 { name => ':authority', value => 'localhost' }, |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
145 { name => 'content-length', value => length($body) }]}); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 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
|
148 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
149 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
|
150 alarm(5); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
151 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
152 $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
|
153 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
154 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
155 }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
156 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
157 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
158 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
159 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
160 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
161 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 log2c("(new connection $client)"); |
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 $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
|
165 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 $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
|
167 pure => 1, preface => "") or return; |
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 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
170 my $frames = $uri eq '/proxy' |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
171 ? $c->read(all => [{ length => 65535 }]) |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
172 : $c->read(all => [{ fin => 1 }]); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 if (!$extra{reuse}) { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 $c->h2_settings(0); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 $c->h2_settings(1); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 $sid = $frame->{sid}; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 return $frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 }; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 $f->{http_end} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 $c->new_stream({ body_more => 1, headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 { name => ':status', value => '200', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 { name => 'content-type', value => 'application/grpc' }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 ]}, $sid); |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
188 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
189 # 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
|
190 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
191 if ($uri eq '/proxy') { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
192 $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
|
193 $c->h2_window(2**16); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
194 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
|
195 } |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
196 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 $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
|
198 $c->new_stream({ headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 { name => 'grpc-status', value => '0', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 { name => 'grpc-message', value => '', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 ]}, $sid); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 return $s->read(all => [{ fin => 1 }]); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 }; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 return $f; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 sub log2c { Test::Nginx::log_core('||', @_); } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 ############################################################################### |