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.
diff --git a/mirror_proxy.t b/mirror_proxy.t
index c347e25..f760d9d 100644
--- a/mirror_proxy.t
+++ b/mirror_proxy.t
@@ -12,6 +12,8 @@
use Test::More;
+use IO::Select;
+
BEGIN { use FindBin; chdir($FindBin::Bin); }
use lib 'lib';
@@ -59,6 +61,12 @@
proxy_pass http://127.0.0.1:8082;
limit_req zone=slow burst=1;
}
+
+ location /mirror/off {
+ internal;
+ proxy_pass http://127.0.0.1:8082;
+ proxy_set_header Content-Length "";
+ }
}
server {
@@ -67,7 +75,6 @@
server_name localhost;
location / {
- client_body_timeout 1s;
proxy_pass http://127.0.0.1:$server_port/return204;
access_log %%TESTDIR%%/test.log test;
add_header X-Body $request_body;
@@ -90,19 +97,10 @@
# delayed subrequest should not affect main request processing nor stuck itself
-SKIP: {
-skip 'hang on win32', 1 if $^O eq 'MSWin32' and !$ENV{TEST_NGINX_UNSAFE};
+my $s = http_post('/delay?1', start => 1);
+like(read_keepalive($s), qr/X-Body: 1234567890\x0d?$/m, 'mirror delay');
-TODO: {
-local $TODO = 'not yet';
-
-like(http_post('/delay?1'), qr/X-Body: 1234567890\x0d?$/m, 'mirror delay');
-
-}
-
-}
-
-$t->todo_alerts() unless $^O eq 'MSWin32';
+$t->todo_alerts();
$t->stop();
my $log = $t->read_file('test.log');
@@ -114,9 +112,9 @@
###############################################################################
sub http_post {
- my ($url) = @_;
+ my ($url, %extra) = @_;
- http(<<EOF);
+ http(<<EOF, %extra);
POST $url HTTP/1.0
Host: localhost
Content-Length: 10
@@ -125,4 +123,18 @@
EOF
}
+sub read_keepalive {
+ my ($s) = @_;
+ my $data = '';
+
+ while (IO::Select->new($s)->can_read(3)) {
+ sysread($s, my $buffer, 4096) or last;
+ $data .= $buffer;
+ last if $data =~ /^\x0d\x0a/ms;
+ }
+
+ log_in($data);
+ return $data;
+}
+
###############################################################################