Mercurial > hg > nginx-tests
annotate fastcgi.t @ 1701:408fe0dd3fed
Tests: fixed mail_imap_ssl.t too long shutdown.
Prior to literals support in IMAP test backend (e7f0b4ca0a1a), early backend
response was treated as invalid, with subsequent proxy connection close.
Now that the connection continues successfully, this requires connection
close before nginx shutdown. Otherwise, it would wait for proxy_timeout.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 17 Jun 2021 19:52:36 +0300 |
parents | 5ac92857e419 |
children |
rev | line source |
---|---|
30 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for fastcgi backend. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require FCGI; }; | |
31
baf9c51d166c
Tests: fix typo in fastcgi test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
30
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
221
8d2c6358d830
Tests: avoid using FCGI on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
212
diff
changeset
|
26 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
30 | 27 |
1463
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(8) |
30 | 29 ->write_file_expand('nginx.conf', <<'EOF'); |
30 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
31 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
32 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
221
diff
changeset
|
33 daemon off; |
30 | 34 |
35 events { | |
36 } | |
37 | |
38 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
40 |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
41 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 server 127.0.0.1:8081; |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
43 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
44 |
30 | 45 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen 127.0.0.1:8080; |
30 | 47 server_name localhost; |
48 | |
49 location / { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 fastcgi_pass 127.0.0.1:8081; |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
51 fastcgi_param REQUEST_URI $request_uri; |
30 | 52 } |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
53 |
1463
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
54 location /catch { |
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
55 fastcgi_pass 127.0.0.1:8081; |
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
56 fastcgi_param REQUEST_URI "/stderr"; |
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
57 fastcgi_catch_stderr sample; |
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
58 } |
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
59 |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
60 location /var { |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
61 fastcgi_pass $arg_b; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
62 fastcgi_param REQUEST_URI $request_uri; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
63 } |
30 | 64 } |
65 } | |
66 | |
67 EOF | |
68 | |
69 $t->run_daemon(\&fastcgi_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
30 | 71 |
72 ############################################################################### | |
73 | |
74 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
75 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect'); |
30 | 76 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); |
77 | |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
78 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD'); |
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
79 |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
80 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled'); |
1463
5ac92857e419
Tests: fastcgi_catch_stderr test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
81 like(http_get('/catch'), qr/502 Bad/, 'catch stderr'); |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
82 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 like(http_get('/var?b=127.0.0.1:' . port(8081)), qr/SEE-THIS/, |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
802
diff
changeset
|
84 'fastcgi with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
85 like(http_get('/var?b=u'), qr/SEE-THIS/, 'fastcgi with variables to upstream'); |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
86 |
30 | 87 ############################################################################### |
88 | |
89 sub fastcgi_daemon { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
30 | 91 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
92 $socket); | |
93 | |
94 my $count; | |
95 while( $request->Accept() >= 0 ) { | |
40 | 96 $count++; |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
97 |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
98 if ($ENV{REQUEST_URI} eq '/stderr') { |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
99 warn "sample stderr text" x 512; |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
100 } |
212 | 101 |
40 | 102 print <<EOF; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
802
diff
changeset
|
103 Location: http://localhost/redirect |
40 | 104 Content-Type: text/html |
105 | |
106 SEE-THIS | |
107 $count | |
108 EOF | |
30 | 109 } |
110 | |
111 FCGI::CloseSocket($socket); | |
112 } | |
113 | |
114 ############################################################################### |