Mercurial > hg > nginx-tests
annotate fastcgi_keepalive.t @ 272:957fe2a76aa7
Tests: remove conditional startup from upstream keepalive tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 21 Mar 2013 20:40:26 +0400 |
parents | 9f0ed4d54ae3 |
children | 36c75df75ca4 |
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 |
272
957fe2a76aa7
Tests: remove conditional startup from upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
24 my $t = Test::Nginx->new()->write_file_expand('nginx.conf', <<'EOF')->plan(6); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 %%TEST_GLOBALS%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 daemon off; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 events { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 } |
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 http { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 %%TEST_GLOBALS_HTTP%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 upstream backend { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server 127.0.0.1:8081; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 keepalive 1; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 } |
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 server { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 fastcgi_pass backend; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 fastcgi_keep_conn on; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 } |
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 EOF |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 $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
|
55 $t->run(); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 ############################################################################### |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 like(http_get('/redir'), qr/302/, 'fastcgi redirect'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 like(http_get('/'), qr/^request: 3$/m, 'fastcgi third request'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
63 TODO: { |
258
9f0ed4d54ae3
Tests: remove/adjust TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
251
diff
changeset
|
64 local $TODO = 'not yet' unless $t->has_version('1.3.12'); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
65 |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 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
|
67 |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
68 } |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
69 |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 # New connection to fastcgi application should be established after HEAD |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 # 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
|
72 # body). |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 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
|
75 |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
76 TODO: { |
258
9f0ed4d54ae3
Tests: remove/adjust TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
251
diff
changeset
|
77 local $TODO = 'not yet' unless $t->has_version('1.3.12'); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
78 |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 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
|
80 |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
81 } |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
82 |
250
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 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 # 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
|
86 # able to count connections. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 # http://www.fastcgi.com/devkit/doc/fcgi-spec.html |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 sub fastcgi_read_record($) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 my ($socket) = @_; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 my ($n, $h, $header); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 $n = $socket->read($header, 8); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 return undef if !defined $n or $n != 8; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 @{$h}{qw/ version type id clen plen /} = unpack("CCnnC", $header); |
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 $n = $socket->read($h->{content}, $h->{clen}); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 return undef if $n != $h->{clen}; |
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 $n = $socket->read($h->{padding}, $h->{plen}); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 return undef if $n != $h->{plen}; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 $h->{socket} = $socket; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 return $h; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 sub fastcgi_respond($$) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 my ($h, $body) = @_; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 # stdout |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 $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
|
115 length($body), 8)); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 $h->{socket}->write($body); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
117 select(undef, undef, undef, 0.1); |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
118 $h->{socket}->write(pack("xxxxxxxx")); |
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
119 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 # 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
|
122 # 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
|
123 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 my $tt = "test text, just for test"; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 $h->{socket}->write(pack("CCnnCx", $h->{version}, 6, $h->{id}, |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 length($tt . $tt), 0) . $tt); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 select(undef, undef, undef, 0.1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 $h->{socket}->write($tt . pack("CC", $h->{version}, 7)); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 select(undef, undef, undef, 0.1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 $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
|
132 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 $h->{socket}->write($tt); |
251
df984d23f9d1
Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
250
diff
changeset
|
134 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 # close stdout |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 $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
|
138 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 select(undef, undef, undef, 0.1); |
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 # end request |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 $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
|
143 select(undef, undef, undef, 0.1); |
250
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 $h->{socket}->write(pack("NCxxx", 0, 0)); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 sub fastcgi_test_daemon { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 my $server = IO::Socket::INET->new( |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 Proto => 'tcp', |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 LocalAddr => '127.0.0.1:8081', |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 Listen => 5, |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 Reuse => 1 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 ) |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 or die "Can't create listening socket: $!\n"; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 local $SIG{PIPE} = 'IGNORE'; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
158 my $ccount = 0; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
159 my $rcount = 0; |
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 $client = $server->accept()) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 $client->autoflush(1); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 Test::Nginx::log_core('||', "fastcgi connection"); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 $ccount++; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 while (my $h = fastcgi_read_record($client)) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 Test::Nginx::log_core('||', "fastcgi record: " |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 . " $h->{version}, $h->{type}, $h->{id}, " |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 . "'$h->{content}'"); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 # skip everything unless stdin, then respond |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 next if $h->{type} != 5; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 $rcount++; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 # respond |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 fastcgi_respond($h, <<EOF); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 Location: http://localhost:8080/redirect |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 Content-Type: text/html |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 SEE-THIS |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 request: $rcount |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 connection: $ccount |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 EOF |
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 close $client; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 ############################################################################### |