Mercurial > hg > nginx-tests
comparison mirror_proxy.t @ 1703:8b7ab9245916
Tests: mirror_proxy.t speedup.
The failing "mirror delay" test doesn't have to wait for a hung connection.
The hang is anyway manifested with a socket leak alert. This eliminates an
unnecessary read timeout delay in the client and allows to enable the test
on win32. Additionally, in the mirror_request_body test, disabled passing
Content-Length to backend to avoid wasting time waiting for an absent body.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 18 Jun 2021 20:02:00 +0300 |
parents | 97c8280de681 |
children |
comparison
equal
deleted
inserted
replaced
1702:f0a02a429a59 | 1703:8b7ab9245916 |
---|---|
9 | 9 |
10 use warnings; | 10 use warnings; |
11 use strict; | 11 use strict; |
12 | 12 |
13 use Test::More; | 13 use Test::More; |
14 | |
15 use IO::Select; | |
14 | 16 |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | 17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
16 | 18 |
17 use lib 'lib'; | 19 use lib 'lib'; |
18 use Test::Nginx; | 20 use Test::Nginx; |
57 location /mirror { | 59 location /mirror { |
58 internal; | 60 internal; |
59 proxy_pass http://127.0.0.1:8082; | 61 proxy_pass http://127.0.0.1:8082; |
60 limit_req zone=slow burst=1; | 62 limit_req zone=slow burst=1; |
61 } | 63 } |
64 | |
65 location /mirror/off { | |
66 internal; | |
67 proxy_pass http://127.0.0.1:8082; | |
68 proxy_set_header Content-Length ""; | |
69 } | |
62 } | 70 } |
63 | 71 |
64 server { | 72 server { |
65 listen 127.0.0.1:8081; | 73 listen 127.0.0.1:8081; |
66 listen 127.0.0.1:8082; | 74 listen 127.0.0.1:8082; |
67 server_name localhost; | 75 server_name localhost; |
68 | 76 |
69 location / { | 77 location / { |
70 client_body_timeout 1s; | |
71 proxy_pass http://127.0.0.1:$server_port/return204; | 78 proxy_pass http://127.0.0.1:$server_port/return204; |
72 access_log %%TESTDIR%%/test.log test; | 79 access_log %%TESTDIR%%/test.log test; |
73 add_header X-Body $request_body; | 80 add_header X-Body $request_body; |
74 } | 81 } |
75 | 82 |
88 like(http_post('/'), qr/X-Body: 1234567890\x0d?$/m, 'mirror proxy'); | 95 like(http_post('/'), qr/X-Body: 1234567890\x0d?$/m, 'mirror proxy'); |
89 like(http_post('/off'), qr/X-Body: 1234567890\x0d?$/m, 'mirror_request_body'); | 96 like(http_post('/off'), qr/X-Body: 1234567890\x0d?$/m, 'mirror_request_body'); |
90 | 97 |
91 # delayed subrequest should not affect main request processing nor stuck itself | 98 # delayed subrequest should not affect main request processing nor stuck itself |
92 | 99 |
93 SKIP: { | 100 my $s = http_post('/delay?1', start => 1); |
94 skip 'hang on win32', 1 if $^O eq 'MSWin32' and !$ENV{TEST_NGINX_UNSAFE}; | 101 like(read_keepalive($s), qr/X-Body: 1234567890\x0d?$/m, 'mirror delay'); |
95 | 102 |
96 TODO: { | 103 $t->todo_alerts(); |
97 local $TODO = 'not yet'; | |
98 | |
99 like(http_post('/delay?1'), qr/X-Body: 1234567890\x0d?$/m, 'mirror delay'); | |
100 | |
101 } | |
102 | |
103 } | |
104 | |
105 $t->todo_alerts() unless $^O eq 'MSWin32'; | |
106 $t->stop(); | 104 $t->stop(); |
107 | 105 |
108 my $log = $t->read_file('test.log'); | 106 my $log = $t->read_file('test.log'); |
109 like($log, qr!^/:1234567890$!m, 'log - request body'); | 107 like($log, qr!^/:1234567890$!m, 'log - request body'); |
110 like($log, qr!^/mirror:1234567890$!m, 'log - request body in mirror'); | 108 like($log, qr!^/mirror:1234567890$!m, 'log - request body in mirror'); |
112 like($log, qr!^/mirror/off:-$!m,, 'log - mirror_request_body off in mirror'); | 110 like($log, qr!^/mirror/off:-$!m,, 'log - mirror_request_body off in mirror'); |
113 | 111 |
114 ############################################################################### | 112 ############################################################################### |
115 | 113 |
116 sub http_post { | 114 sub http_post { |
117 my ($url) = @_; | 115 my ($url, %extra) = @_; |
118 | 116 |
119 http(<<EOF); | 117 http(<<EOF, %extra); |
120 POST $url HTTP/1.0 | 118 POST $url HTTP/1.0 |
121 Host: localhost | 119 Host: localhost |
122 Content-Length: 10 | 120 Content-Length: 10 |
123 | 121 |
124 1234567890 | 122 1234567890 |
125 EOF | 123 EOF |
126 } | 124 } |
127 | 125 |
126 sub read_keepalive { | |
127 my ($s) = @_; | |
128 my $data = ''; | |
129 | |
130 while (IO::Select->new($s)->can_read(3)) { | |
131 sysread($s, my $buffer, 4096) or last; | |
132 $data .= $buffer; | |
133 last if $data =~ /^\x0d\x0a/ms; | |
134 } | |
135 | |
136 log_in($data); | |
137 return $data; | |
138 } | |
139 | |
128 ############################################################################### | 140 ############################################################################### |