annotate fastcgi_keepalive.t @ 273:36c75df75ca4

Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 21 Mar 2013 21:02:15 +0400
parents 957fe2a76aa7
children 6cbcfb4ef7ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
273
36c75df75ca4 Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 272
diff changeset
57 $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
58 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
59
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 ###############################################################################
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 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 like(http_get('/redir'), qr/302/, 'fastcgi redirect');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 like(http_get('/'), qr/^request: 3$/m, 'fastcgi third request');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
251
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
66 TODO: {
258
9f0ed4d54ae3 Tests: remove/adjust TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents: 251
diff changeset
67 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
68
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 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
70
251
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
71 }
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
72
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 # New connection to fastcgi application should be established after HEAD
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 # 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
75 # body).
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 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
78
251
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
79 TODO: {
258
9f0ed4d54ae3 Tests: remove/adjust TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents: 251
diff changeset
80 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
81
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 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
83
251
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
84 }
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
85
250
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
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 # 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
89 # able to count connections.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 # http://www.fastcgi.com/devkit/doc/fcgi-spec.html
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 sub fastcgi_read_record($) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 my ($socket) = @_;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 my ($n, $h, $header);
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 $n = $socket->read($header, 8);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 return undef if !defined $n or $n != 8;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 @{$h}{qw/ version type id clen plen /} = unpack("CCnnC", $header);
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->{content}, $h->{clen});
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104 return undef if $n != $h->{clen};
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 $n = $socket->read($h->{padding}, $h->{plen});
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 return undef if $n != $h->{plen};
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 $h->{socket} = $socket;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110 return $h;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 }
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 sub fastcgi_respond($$) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 my ($h, $body) = @_;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116 # stdout
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 $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
118 length($body), 8));
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 $h->{socket}->write($body);
251
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
120 select(undef, undef, undef, 0.1);
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
121 $h->{socket}->write(pack("xxxxxxxx"));
df984d23f9d1 Tests: improve fastcgi keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
122 select(undef, undef, undef, 0.1);
250
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 # 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
125 # 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
126
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127 my $tt = "test text, just for test";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129 $h->{socket}->write(pack("CCnnCx", $h->{version}, 6, $h->{id},
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
130 length($tt . $tt), 0) . $tt);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
131 select(undef, undef, undef, 0.1);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132 $h->{socket}->write($tt . pack("CC", $h->{version}, 7));
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 $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
135 select(undef, undef, undef, 0.1);
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
136 $h->{socket}->write($tt);
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
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
139 # close stdout
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
140 $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
141
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
142 select(undef, undef, undef, 0.1);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
143
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
144 # end request
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
145 $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
146 select(undef, undef, undef, 0.1);
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
147 $h->{socket}->write(pack("NCxxx", 0, 0));
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
148 }
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 sub fastcgi_test_daemon {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
151 my $server = IO::Socket::INET->new(
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
152 Proto => 'tcp',
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
153 LocalAddr => '127.0.0.1:8081',
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
154 Listen => 5,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
155 Reuse => 1
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
156 )
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
157 or die "Can't create listening socket: $!\n";
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 local $SIG{PIPE} = 'IGNORE';
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 my $ccount = 0;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
162 my $rcount = 0;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
163
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
164 while (my $client = $server->accept()) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
165 $client->autoflush(1);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
166 Test::Nginx::log_core('||', "fastcgi connection");
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
167
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
168 $ccount++;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
169
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
170 while (my $h = fastcgi_read_record($client)) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
171 Test::Nginx::log_core('||', "fastcgi record: "
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
172 . " $h->{version}, $h->{type}, $h->{id}, "
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
173 . "'$h->{content}'");
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 # skip everything unless stdin, then respond
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
176 next if $h->{type} != 5;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
177
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
178 $rcount++;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
179
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
180 # respond
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
181 fastcgi_respond($h, <<EOF);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
182 Location: http://localhost:8080/redirect
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
183 Content-Type: text/html
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
184
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
185 SEE-THIS
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
186 request: $rcount
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
187 connection: $ccount
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
188 EOF
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
273
36c75df75ca4 Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 272
diff changeset
191 $ccount-- unless $rcount;
36c75df75ca4 Tests: fix startup race in fastcgi_keepalive.t, proxy_keepalive.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 272
diff changeset
192
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
193 close $client;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
194 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
195 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
196
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
197 ###############################################################################