Mercurial > hg > nginx-tests
annotate fastcgi.t @ 836:a9c4cebcfe69
Tests: adjusted http resolver test with resend.
Don't bother with socket error to force resolver resend. Nginx doesn't handle
well ECONNREFUSED send() error, which results in "500 Internal Server Error".
It may deserve a separate test, though.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 Jan 2016 00:40:05 +0300 |
parents | eca9b1d19021 |
children | e9064d691790 |
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 |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(7) |
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 { |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
42 server 127.0.0.1:8081; |
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 { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
46 listen 127.0.0.1:8080; |
30 | 47 server_name localhost; |
48 | |
49 location / { | |
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 |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
54 location /var { |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
55 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
|
56 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
|
57 } |
30 | 58 } |
59 } | |
60 | |
61 EOF | |
62 | |
63 $t->run_daemon(\&fastcgi_daemon); | |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
64 $t->run()->waitforsocket('127.0.0.1:8081'); |
30 | 65 |
66 ############################################################################### | |
67 | |
68 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
|
69 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect'); |
30 | 70 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); |
71 | |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
72 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
|
73 |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
74 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled'); |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
75 |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
76 like(http_get('/var?b=127.0.0.1:8081'), qr/SEE-THIS/, 'fastcgi with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
77 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
|
78 |
30 | 79 ############################################################################### |
80 | |
81 sub fastcgi_daemon { | |
44
daa295331acd
Tests: don't bind backend daemons to *, use 127.0.0.1 instead.
Maxim Dounin <mdounin@mdounin.ru>
parents:
41
diff
changeset
|
82 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
30 | 83 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
84 $socket); | |
85 | |
86 my $count; | |
87 while( $request->Accept() >= 0 ) { | |
40 | 88 $count++; |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
89 |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
90 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
|
91 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
|
92 } |
212 | 93 |
40 | 94 print <<EOF; |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
95 Location: http://127.0.0.1:8080/redirect |
40 | 96 Content-Type: text/html |
97 | |
98 SEE-THIS | |
99 $count | |
100 EOF | |
30 | 101 } |
102 | |
103 FCGI::CloseSocket($socket); | |
104 } | |
105 | |
106 ############################################################################### |