Mercurial > hg > nginx-tests
annotate grpc_request_buffering.t @ 1995:d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Both "cat" and "grep" might not be available on Windows. Instead,
$t->read_file() is used, as it is already used in other places. To
simplify checking logs as previously done with "grep", $t->grep_file()
helper function is introduced.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Aug 2024 05:18:51 +0300 |
parents | 11463d379570 |
children |
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 { |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
41 listen 127.0.0.1:8080; |
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 |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
45 http2 on; |
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
46 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location /mirror { } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 location / { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 grpc_pass 127.0.0.1:8081; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 add_header X-Body $request_body; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 mirror /mirror; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
54 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
55 location /proxy { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
56 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
|
57 proxy_intercept_errors on; |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
58 error_page 404 = @fallback; |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
59 } |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
60 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
61 location @fallback { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
62 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
|
63 } |
1311
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 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1356
diff
changeset
|
69 $t->run(); |
1311
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 ############################################################################### |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 my $p = port(8081); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 my $f = grpc(); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 my $frames = $f->{http_start}('/SayHello'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 is($frame->{flags}, 4, 'request - HEADERS flags'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 is($frame->{headers}{':method'}, 'POST', 'request - method'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 is($frame->{headers}{':scheme'}, 'http', 'request - scheme'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 is($frame->{headers}{':path'}, '/SayHello', 'request - path'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 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
|
83 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 is($frame->{data}, 'Hello', 'request - DATA'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 is($frame->{length}, 5, 'request - DATA length'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 is($frame->{flags}, 1, 'request - DATA flags'); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $frames = $f->{http_end}(); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 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
|
92 |
1356
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
93 # 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
|
94 # 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
|
95 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
96 $frames = $f->{http_start}('/proxy'); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
97 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
|
98 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
|
99 |
1356
ca6fe31f74c4
Tests: TODO grpc request body "first body bytes" test on FreeBSD.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1353
diff
changeset
|
100 # 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
|
101 # 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
|
102 # 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
|
103 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
104 $frames = $f->{http_end}(); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
105 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
|
106 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
|
107 |
1995
d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1986
diff
changeset
|
108 is($t->grep_file('error.log', '[crit]'), '', 'no crit'); |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
109 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 sub grpc { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 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
|
114 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 $server = IO::Socket::INET->new( |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 Proto => 'tcp', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 LocalHost => '127.0.0.1', |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 LocalPort => $p, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 Listen => 5, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 Reuse => 1 |
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 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
|
123 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $f->{http_start} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 ($uri, my %extra) = @_; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 $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
|
127 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
|
128 $s->new_stream({ body => $body, headers => [ |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 { name => ':method', value => 'POST', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 { name => ':scheme', value => 'http', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 { name => ':path', value => $uri }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 { name => ':authority', value => 'localhost' }, |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
133 { name => 'content-length', value => length($body) }]}); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 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
|
136 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
137 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
|
138 alarm(5); |
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 $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
|
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 }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
144 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
145 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
146 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
147 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
148 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1311
diff
changeset
|
149 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 log2c("(new connection $client)"); |
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 $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
|
153 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 $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
|
155 pure => 1, preface => "") or return; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
1353
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
158 my $frames = $uri eq '/proxy' |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
159 ? $c->read(all => [{ length => 65535 }]) |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
160 : $c->read(all => [{ fin => 1 }]); |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 if (!$extra{reuse}) { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $c->h2_settings(0); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 $c->h2_settings(1); |
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 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 $sid = $frame->{sid}; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 return $frames; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 }; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 $f->{http_end} = sub { |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 $c->new_stream({ body_more => 1, headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 { name => ':status', value => '200', mode => 0 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 { name => 'content-type', value => 'application/grpc' }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 ]}, $sid); |
1353
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 # 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
|
178 |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
179 if ($uri eq '/proxy') { |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
180 $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
|
181 $c->h2_window(2**16); |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
182 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
|
183 } |
65730ba03b42
Tests: body cleanup test with preserve_output (ticket #1565).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
184 |
1311
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 $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
|
186 $c->new_stream({ headers => [ |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 { name => 'grpc-status', value => '0', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 { name => 'grpc-message', value => '', mode => 2 }, |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 ]}, $sid); |
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 $s->read(all => [{ fin => 1 }]); |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 }; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 return $f; |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 sub log2c { Test::Nginx::log_core('||', @_); } |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
4979af9fd905
Tests: grpc request buffering and next upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 ############################################################################### |