annotate fastcgi_body2.t @ 1248:70192b1baf01

Tests: added exception test to stream_js.t using 'require'. The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't currently provide an easy way to check its version, whilst we are obligated to gracefully handle such cases somehow. With such an addition of 'require', now the tests are skipped instead on the previous versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Nov 2017 13:16:39 +0300
parents 1a820a5a32ae
children 42d9fd20eeb6
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 {
1040
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
45 server 127.0.0.1:8081;
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
46 server 127.0.0.1:8082 backup;
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
47 }
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
48
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
49 upstream u2 {
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
50 server 127.0.0.1:8081;
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
51 server 127.0.0.1:8082 backup;
433
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
55 listen 127.0.0.1:8080;
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 server_name localhost;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location / {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 fastcgi_pass u;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 fastcgi_param REQUEST_URI $request_uri;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 fastcgi_param CONTENT_LENGTH $content_length;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 # fastcgi_next_upstream error timeout;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 fastcgi_read_timeout 1s;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
65
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
66 location /in_memory {
1040
1a820a5a32ae Tests: do not depend on peer selection order in fastcgi_body2.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
67 fastcgi_pass u2;
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
68 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
69 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
70 # fastcgi_next_upstream error timeout;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
71 fastcgi_read_timeout 1s;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
72 client_body_buffer_size 128k;
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
73 }
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 EOF
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
79 $t->run_daemon(\&fastcgi_daemon, port(8081));
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
80 $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
81 $t->run();
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
83 $t->waitforsocket('127.0.0.1:' . port(8081));
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
84 $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
85
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 ###############################################################################
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
461
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
88 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
89 'body length - in file');
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
90
67f41a61307c Tests: added fastcgi test for request body in memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 433
diff changeset
91 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
92 'body length - in memory');
433
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 sub http_get_length {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 my ($url, $body) = @_;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 my $length = length $body;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 return http(<<EOF);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 GET $url HTTP/1.0
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 Host: localhost
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 Content-Length: $length
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 $body
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 EOF
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 sub fastcgi_daemon {
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 my ($port) = @_;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 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
113 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
114 $socket);
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 while( $request->Accept() >= 0 ) {
925
6bb1f2ccd386 Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 568
diff changeset
117 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
118 my $len = length $body;
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
120 sleep 3 if $port == port(8081);
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 print <<EOF;
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 925
diff changeset
123 Location: http://localhost/redirect
433
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 Content-Type: text/html
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 X-Length: $len
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 EOF
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 FCGI::CloseSocket($socket);
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
4a045c74a77c Tests: request body test with fastcgi_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 ###############################################################################