Mercurial > hg > nginx-tests
annotate fastcgi_keepalive.t @ 281:53068d38a3ce
Tests: truncate messages to 2048 bytes instead of 4096.
The latter causes TAP parsing problems on CentOS 5 and 6.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 16 Apr 2013 17:38:11 +0400 |
parents | 94f8ee2f6688 |
children | 6fe0459b6668 |
rev | line source |
---|---|
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend with keepalive. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
275
6cbcfb4ef7ee
Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
273
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http fastcgi upstream_keepalive/)->plan(6) |
6cbcfb4ef7ee
Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
273
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 upstream backend { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server 127.0.0.1:8081; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 keepalive 1; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 fastcgi_pass backend; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 fastcgi_keep_conn on; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 EOF |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 $t->run_daemon(\&fastcgi_test_daemon); |
272
957fe2a76aa7
Tests: remove conditional startup from upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
56 $t->run(); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
273
36c75df75ca4
Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
272
diff
changeset
|
58 $t->waitforsocket('127.0.0.1:8081') |
36c75df75ca4
Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
272
diff
changeset
|
59 or die "Can't start test backend"; |
36c75df75ca4
Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
272
diff
changeset
|
60 |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 ############################################################################### |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 like(http_get('/redir'), qr/302/, 'fastcgi redirect'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 like(http_get('/'), qr/^request: 3$/m, 'fastcgi third request'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 like(http_get('/single'), qr/^connection: 1$/m, 'single connection used'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 # New connection to fastcgi application should be established after HEAD |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 # requests since nginx doesn't read whole response (as it doesn't need |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 # body). |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 unlike(http_head('/head'), qr/SEE-THIS/, 'no data in HEAD'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 like(http_get('/after'), qr/^connection: 2$/m, 'new connection after HEAD'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 ############################################################################### |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 # Simple FastCGI responder implementation. Unlike FCGI and FCGI::Async it's |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 # able to count connections. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 # http://www.fastcgi.com/devkit/doc/fcgi-spec.html |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 sub fastcgi_read_record($) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 my ($socket) = @_; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 my ($n, $h, $header); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 $n = $socket->read($header, 8); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 return undef if !defined $n or $n != 8; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 @{$h}{qw/ version type id clen plen /} = unpack("CCnnC", $header); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 $n = $socket->read($h->{content}, $h->{clen}); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 return undef if $n != $h->{clen}; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 $n = $socket->read($h->{padding}, $h->{plen}); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 return undef if $n != $h->{plen}; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 $h->{socket} = $socket; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 return $h; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 sub fastcgi_respond($$) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 my ($h, $body) = @_; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 # stdout |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 $h->{socket}->write(pack("CCnnCx", $h->{version}, 6, $h->{id}, |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
109 length($body), 8)); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 $h->{socket}->write($body); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
111 select(undef, undef, undef, 0.1); |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
112 $h->{socket}->write(pack("xxxxxxxx")); |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
113 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 # write some text to stdout and stderr splitted over multiple network |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 # packets to test if we correctly set pipe length in various places |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 my $tt = "test text, just for test"; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 $h->{socket}->write(pack("CCnnCx", $h->{version}, 6, $h->{id}, |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 length($tt . $tt), 0) . $tt); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 select(undef, undef, undef, 0.1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 $h->{socket}->write($tt . pack("CC", $h->{version}, 7)); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 select(undef, undef, undef, 0.1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 $h->{socket}->write(pack("nnCx", $h->{id}, length($tt), 0)); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
126 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 $h->{socket}->write($tt); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
128 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 # close stdout |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 $h->{socket}->write(pack("CCnnCx", $h->{version}, 6, $h->{id}, 0, 0)); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 select(undef, undef, undef, 0.1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 # end request |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 $h->{socket}->write(pack("CCnnCx", $h->{version}, 3, $h->{id}, 8, 0)); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
137 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
138 $h->{socket}->write(pack("NCxxx", 0, 0)); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 sub fastcgi_test_daemon { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 my $server = IO::Socket::INET->new( |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 Proto => 'tcp', |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 LocalAddr => '127.0.0.1:8081', |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 Listen => 5, |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 Reuse => 1 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 ) |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 or die "Can't create listening socket: $!\n"; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 local $SIG{PIPE} = 'IGNORE'; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 my $ccount = 0; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 my $rcount = 0; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 while (my $client = $server->accept()) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 $client->autoflush(1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 Test::Nginx::log_core('||', "fastcgi connection"); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
158 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
159 $ccount++; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
160 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 while (my $h = fastcgi_read_record($client)) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 Test::Nginx::log_core('||', "fastcgi record: " |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 . " $h->{version}, $h->{type}, $h->{id}, " |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 . "'$h->{content}'"); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 # skip everything unless stdin, then respond |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 next if $h->{type} != 5; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 $rcount++; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 # respond |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 fastcgi_respond($h, <<EOF); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 Location: http://localhost:8080/redirect |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 Content-Type: text/html |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 SEE-THIS |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 request: $rcount |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 connection: $ccount |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 EOF |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 |
273
36c75df75ca4
Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
272
diff
changeset
|
182 $ccount-- unless $rcount; |
36c75df75ca4
Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
272
diff
changeset
|
183 |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 close $client; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 ############################################################################### |