annotate fastcgi_body2.t @ 974:882267679006

Tests: simplified parallel modifications in tests. Mail tests were simplified in c227348453db.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 12 Jul 2016 17:39:03 +0300
parents e9064d691790
children 1a820a5a32ae
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 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
45 server 127.0.0.1:8081 max_fails=0;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
46 server 127.0.0.1:8082;
433
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 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
50 listen 127.0.0.1:8080;
433
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
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
74 $t->run_daemon(\&fastcgi_daemon, port(8081));
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
75 $t->run_daemon(\&fastcgi_daemon, port(8082));
433
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
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
78 $t->waitforsocket('127.0.0.1:' . port(8081));
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
79 $t->waitforsocket('127.0.0.1:' . port(8082));
433
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 while( $request->Accept() >= 0 ) {
925
6bb1f2ccd386 Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 568
diff changeset
116 read(STDIN, my $body, $ENV{'CONTENT_LENGTH'});
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 my $len = length $body;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
119 sleep 3 if $port == port(8081);
433
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 print <<EOF;
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 925
diff changeset
122 Location: http://localhost/redirect
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 Content-Type: text/html
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 X-Length: $len
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 EOF
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 FCGI::CloseSocket($socket);
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 ###############################################################################