[PATCH 1 of 1] Test proxy_unfinished: limit buffers to force buffering on no proxy temp
Markus Linnala
Markus.Linnala at cybercom.com
Tue Apr 15 12:26:26 UTC 2014
# HG changeset patch
# User Markus Linnala <Markus.Linnala at cybercom.com>
# Date 1397505734 -10800
# Mon Apr 14 23:02:14 2014 +0300
# Node ID cf54213675d59b801bee34328223c28f992cf8c7
# Parent 74a015aad3521ffef6b404cdaa9eafd991824301
Test proxy_unfinished: limit buffers to force buffering on no proxy temp
With some systems (Fedora-20 Linux 3.13) socket buffers are huge and
nginx does not use temp files when proxying. Set buffer sizes to small
values to make use of temp files more probable. Currently there is no
way to force temp buffers.
no proxy temp should fail on 1.5.2 and work okay on later versions.
sub_filter forces chunked encoding and so it is possible to notice
problem because last chunk is 0 chunk when there is error.
Only use limited buffers on 'no proxy temp' as other tests fail
because tests take too long.
http://trac.nginx.org/nginx/ticket/541
diff -r 74a015aad352 -r cf54213675d5 proxy_unfinished.t
--- a/proxy_unfinished.t Mon Mar 17 16:02:19 2014 +0400
+++ b/proxy_unfinished.t Mon Apr 14 23:02:14 2014 +0300
@@ -19,7 +19,7 @@
use Test::More;
-use Socket qw/ CRLF /;
+use Socket qw/ CRLF SOL_SOCKET SO_RCVBUF /;
BEGIN { use FindBin; chdir($FindBin::Bin); }
@@ -33,7 +33,7 @@
plan(skip_all => 'win32') if $^O eq 'MSWin32';
-my $t = Test::Nginx->new()->has(qw/http proxy cache sub/)->plan(15)
+my $t = Test::Nginx->new()->has(qw/http proxy cache sub/)->plan(16)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -72,6 +72,15 @@
add_header X-Cache-Status $upstream_cache_status;
}
+ location /local/ {
+ alias %%TESTDIR%%/;
+ }
+ }
+
+ server {
+ listen 127.0.0.1:8082 sndbuf=4096;
+ server_name localhost;
+
location /proxy/ {
sub_filter foo bar;
sub_filter_types *;
@@ -79,10 +88,6 @@
proxy_buffer_size 1k;
proxy_buffers 4 1k;
}
-
- location /local/ {
- alias %%TESTDIR%%/;
- }
}
}
@@ -159,8 +164,22 @@
# no final chunk
chmod(0000, $t->testdir() . '/proxy_temp');
-like(http_get_11('/proxy/big.html', sleep => 0.5),
- qr/X(?!.*\x0d\x0a?0\x0d\x0a?)/s, 'no proxy temp');
+# Limit socket buffers here and listen to force buffering to temp file.
+like(http_get_11('/proxy/big.html',
+ socket =>
+ do {
+ my $s = IO::Socket::INET->new(
+ Proto => 'tcp',
+ PeerAddr => '127.0.0.1:8082'
+ )
+ or die "Can't connect to nginx: $!\n";
+ $s->setsockopt(SOL_SOCKET, SO_RCVBUF, 1) or die;
+ $s;
+ }),
+ qr/X(?:\x0d\x0a?)?$/s, 'no proxy temp');
+
+# If this test fails, previous test did not test buffering properly
+is(lines($t, 'error.log', '\[crit\] .*? open\(\) .*? failed .*? request: "GET /proxy/big\.html HTTP/1\.1"'), 1, "no proxy temp actual");
}
@@ -270,3 +289,17 @@
}
###############################################################################
+
+# from error_log.t
+
+sub lines {
+ my ($t, $file, $pattern) = @_;
+
+ my $path = $t->testdir() . '/' . $file;
+ open my $fh, '<', $path or return "$!";
+ my $value = map { $_ =~ /$pattern/ } (<$fh>);
+ close $fh;
+ return $value;
+}
+
+###############################################################################
More information about the nginx-devel
mailing list