annotate proxy_cache_lock.t @ 397:847ea345becb

Tests: removed TODO and try_run() checks for legacy versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 05 May 2014 11:46:01 +0400
parents c28ecaef065f
children 60888e2c3f5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for http proxy cache lock.
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13 use Socket qw/ CRLF /;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use lib 'lib';
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18 use Test::Nginx;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDERR; $| = 1;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23 select STDOUT; $| = 1;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24
223
f9325406df0b Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 213
diff changeset
25 plan(skip_all => 'win32') if $^O eq 'MSWin32';
f9325406df0b Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 213
diff changeset
26
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http proxy cache/)
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30 %%TEST_GLOBALS%%
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31
249
6a0d934950bc Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents: 233
diff changeset
32 daemon off;
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 events {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 http {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 %%TEST_GLOBALS_HTTP%%
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40 proxy_cache_path %%TESTDIR%%/cache levels=1:2
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 keys_zone=NAME:10m;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 server {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 listen 127.0.0.1:8080;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 server_name localhost;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 location / {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 proxy_pass http://127.0.0.1:8081;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 proxy_cache NAME;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 proxy_cache_lock on;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 location /timeout {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 proxy_pass http://127.0.0.1:8081;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 proxy_cache NAME;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 proxy_cache_lock on;
233
1a5574d84917 Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents: 223
diff changeset
59 proxy_cache_lock_timeout 200ms;
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 location /nolock {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 proxy_pass http://127.0.0.1:8081;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 proxy_cache NAME;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 EOF
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 $t->run_daemon(\&http_fake_daemon);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
397
847ea345becb Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 392
diff changeset
73 $t->run()->plan(19);
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74
213
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
75 $t->waitforsocket('127.0.0.1:8081');
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 # sequentional requests
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 like(http_get('/seq'), qr/request 1/, 'sequentional request ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 # parallel requests
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 my @sockets;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90 $sockets[$i] = http_start('/par1');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 like(http_end($sockets[$i]), qr/request 1/, 'parallel request ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 like(http_get('/par1'), qr/request 1/, 'first request cached');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 # parallel requests with cache lock timeout
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 $sockets[$i] = http_start('/timeout');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106 like(http_end($sockets[$i]), qr/request $i/, 'lock timeout ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109 like(http_get('/timeout'), qr/request 3/, 'lock timeout - last cached');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 # no lock
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 $sockets[$i] = http_start('/nolock');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 like(http_end($sockets[$i]), qr/request $i/, 'nolock ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 like(http_get('/nolock'), qr/request 3/, 'nolock - last cached');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
122
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
123 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125 sub http_start {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126 my ($uri) = @_;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128 my $s;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129 my $request = "GET $uri HTTP/1.0" . CRLF . CRLF;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
130
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
131 eval {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132 local $SIG{ALRM} = sub { die "timeout\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
133 local $SIG{PIPE} = sub { die "sigpipe\n" };
233
1a5574d84917 Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents: 223
diff changeset
134 alarm(3);
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
135 $s = IO::Socket::INET->new(
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
136 Proto => 'tcp',
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
137 PeerAddr => '127.0.0.1:8080'
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
138 );
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
139 log_out($request);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
140 $s->print($request);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
141 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
142 };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
143 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
144 if ($@) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
145 log_in("died: $@");
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
146 return undef;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
147 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
148 return $s;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
149 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
150
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
151 sub http_end {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
152 my ($s) = @_;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
153 my $reply;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
154
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
155 eval {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
156 local $SIG{ALRM} = sub { die "timeout\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
157 local $SIG{PIPE} = sub { die "sigpipe\n" };
233
1a5574d84917 Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents: 223
diff changeset
158 alarm(3);
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
159 local $/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
160 $reply = $s->getline();
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
161 log_in($reply);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
162 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
163 };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
164 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
165 if ($@) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
166 log_in("died: $@");
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
167 return undef;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
168 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
169 return $reply;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
170 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
171
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
172 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
173
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
174 sub http_fake_daemon {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
175 my $server = IO::Socket::INET->new(
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
176 Proto => 'tcp',
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
177 LocalAddr => '127.0.0.1:8081',
191
bc6ecf23cc9c Tests: enlarge listen queue for cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 184
diff changeset
178 Listen => 5,
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
179 Reuse => 1
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
180 )
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
181 or die "Can't create listening socket: $!\n";
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
182
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
183 my $num = 0;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
184 my $uri = '';
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
185
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
186 while (my $client = $server->accept()) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
187 $client->autoflush(1);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
188
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
189 while (<$client>) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
190 if (/GET (.*) HTTP/ && $1 ne $uri) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
191 $uri = $1;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
192 $num = 0;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
193 }
212
a7cc4371f4ad Tests: whitespace fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 191
diff changeset
194
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
195 $uri = $1 if /GET (.*) HTTP/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
196 last if /^\x0d?\x0a?$/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
197 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
198
213
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
199 next unless $uri;
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
200
233
1a5574d84917 Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents: 223
diff changeset
201 select(undef, undef, undef, 0.5);
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
202
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
203 $num++;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
204 print $client <<"EOF";
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
205 HTTP/1.1 200 OK
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
206 Cache-Control: max-age=300
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
207 Connection: close
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
208
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
209 request $num
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
210 EOF
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
211 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
212 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
213
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
214 ###############################################################################