annotate fastcgi_body2.t @ 572:ca54b445d982

Tests: masked nginx bug in proxy next upstream. When iterating through several next upstreams per a worker cycle, a previously reported event about upstream connection error may be improperly applied to the next upstream, thus leading to the invalid connection error. E.g., in kqueue, where the problem is visible, this is caused by "ev->instance" that does not tolerate more than one next upstream at once, and kevents placed on the kqueue separately for read and write events. The change is to limit test case to the only one next upstream.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 14 May 2015 11:54:24 +0300
parents 907e89fba9c3
children 6bb1f2ccd386
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Maxim Dounin
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Sergey Kandaurov
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # Test for fastcgi backend with large request body,
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 # with fastcgi_next_upstream directive.
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use warnings;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use strict;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use Test::More;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 eval { require FCGI; };
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 plan(skip_all => 'FCGI not installed') if $@;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 plan(skip_all => 'win32') if $^O eq 'MSWin32';
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
31 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(2)
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 ->write_file_expand('nginx.conf', <<'EOF');
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 %%TEST_GLOBALS%%
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 daemon off;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 events {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 http {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 upstream u {
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
45 server 127.0.0.1:8081 max_fails=0;
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server 127.0.0.1:8082;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:8080;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server_name localhost;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 location / {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 fastcgi_pass u;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 fastcgi_param REQUEST_URI $request_uri;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 fastcgi_param CONTENT_LENGTH $content_length;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 # fastcgi_next_upstream error timeout;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 fastcgi_read_timeout 1s;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
60
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
61 location /in_memory {
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
62 fastcgi_pass u;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
63 fastcgi_param REQUEST_URI $request_uri;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
64 fastcgi_param CONTENT_LENGTH $content_length;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
65 # fastcgi_next_upstream error timeout;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
66 fastcgi_read_timeout 1s;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
67 client_body_buffer_size 128k;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
68 }
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 EOF
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 $t->run_daemon(\&fastcgi_daemon, 8081);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $t->run_daemon(\&fastcgi_daemon, 8082);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 $t->run();
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 $t->waitforsocket('127.0.0.1:8081');
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 $t->waitforsocket('127.0.0.1:8082');
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
83 like(http_get_length('/', 'x' x 102400), qr/X-Length: 102400/,
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
84 'body length - in file');
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
85
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
86 # force quick recovery, so that the next request wouldn't fail
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
87
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
88 http_get('/');
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
89
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
90 like(http_get_length('/in_memory', 'x' x 102400), qr/X-Length: 102400/,
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
91 'body length - in memory');
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 sub http_get_length {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my ($url, $body) = @_;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 my $length = length $body;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 return http(<<EOF);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 GET $url HTTP/1.0
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 Host: localhost
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 Content-Length: $length
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 $body
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 EOF
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 sub fastcgi_daemon {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 my ($port) = @_;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 my $socket = FCGI::OpenSocket("127.0.0.1:$port", 5);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 $socket);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 my ($body, $len);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 while( $request->Accept() >= 0 ) {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 read(STDIN, $body, $ENV{'CONTENT_LENGTH'});
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 my $len = length $body;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 sleep 3 if $port == 8081;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 print <<EOF;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 Location: http://127.0.0.1:8080/redirect
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 Content-Type: text/html
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 X-Length: $len
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 EOF
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 FCGI::CloseSocket($socket);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 ###############################################################################