Mercurial > hg > nginx-tests
annotate fastcgi.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 | d5bf5942a8b2 |
children | d95c4b8e5517 |
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 |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(5) |
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 |
30 | 41 server { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
42 listen 127.0.0.1:8080; |
30 | 43 server_name localhost; |
44 | |
45 location / { | |
46 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
|
47 fastcgi_param REQUEST_URI $request_uri; |
30 | 48 } |
49 } | |
50 } | |
51 | |
52 EOF | |
53 | |
54 $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
|
55 $t->run()->waitforsocket('127.0.0.1:8081'); |
30 | 56 |
57 ############################################################################### | |
58 | |
59 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
|
60 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect'); |
30 | 61 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); |
62 | |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
63 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
|
64 |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
65 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
|
66 |
30 | 67 ############################################################################### |
68 | |
69 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
|
70 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
30 | 71 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
72 $socket); | |
73 | |
74 my $count; | |
75 while( $request->Accept() >= 0 ) { | |
40 | 76 $count++; |
131
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
77 |
21a428b31f37
Tests: add test for fastcgi regression introduced in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
78 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
|
79 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
|
80 } |
212 | 81 |
40 | 82 print <<EOF; |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
83 Location: http://127.0.0.1:8080/redirect |
40 | 84 Content-Type: text/html |
85 | |
86 SEE-THIS | |
87 $count | |
88 EOF | |
30 | 89 } |
90 | |
91 FCGI::CloseSocket($socket); | |
92 } | |
93 | |
94 ############################################################################### |