annotate proxy_cache.t @ 295:6fe0459b6668

Tests: eliminate startup races in proxy and fastcgi tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 08 Jun 2013 07:02:11 +0400
parents 6a0d934950bc
children 44c42894fdfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for http proxy cache.
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
104
8bc9de6559a1 Tests: add gzip module checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 101
diff changeset
12 use Test::More;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
17 use Test::Nginx qw/ :DEFAULT :gzip /;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
223
f9325406df0b Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 178
diff changeset
24 plan(skip_all => 'win32') if $^O eq 'MSWin32';
f9325406df0b Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 178
diff changeset
25
145
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(12)
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 120
diff changeset
27 ->write_file_expand('nginx.conf', <<'EOF');
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
29 %%TEST_GLOBALS%%
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
30
249
6a0d934950bc Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents: 233
diff changeset
31 daemon off;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 events {
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 http {
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
37 %%TEST_GLOBALS_HTTP%%
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 proxy_cache_path %%TESTDIR%%/cache levels=1:2
80
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
40 keys_zone=NAME:10m;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 server {
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 listen 127.0.0.1:8080;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 server_name localhost;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
46 gzip on;
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
47 gzip_min_length 0;
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
48
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 location / {
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 proxy_pass http://127.0.0.1:8081;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 proxy_cache NAME;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
54 proxy_cache_valid 200 302 1s;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 proxy_cache_valid 301 1d;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 proxy_cache_valid any 1m;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 proxy_cache_min_uses 1;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
60 proxy_cache_use_stale error timeout invalid_header http_500
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
61 http_404;
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 }
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
63
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
64 location /fake/ {
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
65 proxy_pass http://127.0.0.1:8082;
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
66 proxy_cache NAME;
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
67 }
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 server {
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 listen 127.0.0.1:8081;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 server_name localhost;
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 location / {
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 }
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 EOF
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 $t->write_file('t.html', 'SEE-THIS');
80
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
81 $t->write_file('t2.html', 'SEE-THIS');
99
f92852da34aa Tests: add test for empty cached response.
Maxim Dounin <mdounin@mdounin.ru>
parents: 80
diff changeset
82 $t->write_file('empty.html', '');
295
6fe0459b6668 Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
83
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
84 $t->run_daemon(\&http_fake_daemon);
295
6fe0459b6668 Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
85 $t->run()->waitforsocket('127.0.0.1:8081');
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 ###############################################################################
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request');
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 $t->write_file('t.html', 'NOOP');
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request cached');
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93
80
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
94 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head request');
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
95 like(http_get('/t2.html'), qr/SEE-THIS/, 'get after head');
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
96 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head after get');
14cf2658592d Tests: add more proxy_cache tests, remove obsolete clean_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 74
diff changeset
97
145
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
98 like(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m, 'cached range');
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
99 like(http_get_range('/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
100 'cached multipart range');
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
101
99
f92852da34aa Tests: add test for empty cached response.
Maxim Dounin <mdounin@mdounin.ru>
parents: 80
diff changeset
102 like(http_get('/empty.html'), qr/HTTP/, 'empty get first');
120
598b758c68a9 Tests: empty cached responses partially fixed in 0.8.31.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
103 like(http_get('/empty.html'), qr/HTTP/, 'empty get second');
598b758c68a9 Tests: empty cached responses partially fixed in 0.8.31.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
104
233
1a5574d84917 Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents: 224
diff changeset
105 select(undef, undef, undef, 1.1);
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
106 unlink $t->testdir() . '/t.html';
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
107 like(http_gzip_request('/t.html'),
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
108 qr/HTTP.*1c\x0d\x0a.{28}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s,
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
109 'non-empty get stale');
120
598b758c68a9 Tests: empty cached responses partially fixed in 0.8.31.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
110
101
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
111 unlink $t->testdir() . '/empty.html';
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
112 like(http_gzip_request('/empty.html'),
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
113 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s,
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
114 'empty get stale');
6303927c18d2 Tests: proxy cache tests for problems with duplicate final chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 99
diff changeset
115
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
116 http_get('/fake/unfinished');
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
117 like(http_get('/fake/unfinished'), qr/unfinished 2/, 'unfinished not cached');
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
118
74
3afbba94c8eb Tests: basic proxy_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 ###############################################################################
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
120
145
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
121 sub http_get_range {
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
122 my ($url, $extra) = @_;
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
123 return http(<<EOF);
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
124 GET $url HTTP/1.1
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
125 Host: localhost
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
126 Connection: close
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
127 $extra
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
128
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
129 EOF
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
130 }
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
131
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
132 ###############################################################################
2ea7cd95ff05 Tests: basic tests for range requests from cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 140
diff changeset
133
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
134 sub http_fake_daemon {
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
135 my $server = IO::Socket::INET->new(
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
136 Proto => 'tcp',
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
137 LocalAddr => '127.0.0.1:8082',
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
138 Listen => 5,
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
139 Reuse => 1
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
140 )
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
141 or die "Can't create listening socket: $!\n";
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
142
295
6fe0459b6668 Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
143 local $SIG{PIPE} = 'IGNORE';
6fe0459b6668 Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
144
140
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
145 my $num = 0;
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
146
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
147 while (my $client = $server->accept()) {
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
148 $client->autoflush(1);
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
149
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
150 while (<$client>) {
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
151 last if (/^\x0d?\x0a?$/);
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
152 }
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
153
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
154 $num++;
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
155 print $client <<"EOF";
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
156 HTTP/1.1 200 OK
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
157 Content-Length: 100
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
158 Cache-Control: max-age=300
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
159 Connection: close
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
160
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
161 unfinished $num
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
162 EOF
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
163 }
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
164 }
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
165
3f246a1be2b0 Tests: unfinished responses shouldn't be cached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 121
diff changeset
166 ###############################################################################