annotate proxy_cache_lock.t @ 223:f9325406df0b

Tests: skip tests not appropriate for win32. Skip tests which doesn't work on win32, notably ones using crypt(), symlinks and shared memory.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 03 Jun 2012 05:20:39 +0400
parents 4ac0807cc3cf
children 1a5574d84917
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
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 daemon off;
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;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 proxy_cache_lock_timeout 300ms;
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
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 eval {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 open OLDERR, ">&", \*STDERR; close STDERR;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 $t->run();
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 open STDERR, ">&", \*OLDERR;
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 plan(skip_all => 'no proxy_cache_lock') if $@;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 $t->plan(19);
213
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
81 $t->waitforsocket('127.0.0.1:8081');
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82
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 # sequentional 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 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 like(http_get('/seq'), qr/request 1/, 'sequentional request ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 # parallel requests
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 my @sockets;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 $sockets[$i] = http_start('/par1');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 }
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 for my $i (1 .. 5) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 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
101 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 like(http_get('/par1'), qr/request 1/, 'first request cached');
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 # parallel requests with cache lock timeout
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108 $sockets[$i] = http_start('/timeout');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109 }
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 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112 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
113 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115 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
116
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 # no lock
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120 $sockets[$i] = http_start('/nolock');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 }
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 for my $i (1 .. 3) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 like(http_end($sockets[$i]), qr/request $i/, 'nolock ' . $i);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127 like(http_get('/nolock'), qr/request 3/, 'nolock - last cached');
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129 ###############################################################################
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 sub http_start {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132 my ($uri) = @_;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
133
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
134 my $s;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
135 my $request = "GET $uri HTTP/1.0" . CRLF . CRLF;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
136
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
137 eval {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
138 local $SIG{ALRM} = sub { die "timeout\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
139 local $SIG{PIPE} = sub { die "sigpipe\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
140 alarm(2);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
141 $s = IO::Socket::INET->new(
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
142 Proto => 'tcp',
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
143 PeerAddr => '127.0.0.1:8080'
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
144 );
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
145 log_out($request);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
146 $s->print($request);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
147 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
148 };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
149 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
150 if ($@) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
151 log_in("died: $@");
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
152 return undef;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
153 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
154 return $s;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
155 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
156
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
157 sub http_end {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
158 my ($s) = @_;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
159 my $reply;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
160
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
161 eval {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
162 local $SIG{ALRM} = sub { die "timeout\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
163 local $SIG{PIPE} = sub { die "sigpipe\n" };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
164 alarm(2);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
165 local $/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
166 $reply = $s->getline();
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
167 log_in($reply);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
168 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
169 };
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
170 alarm(0);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
171 if ($@) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
172 log_in("died: $@");
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
173 return undef;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
174 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
175 return $reply;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
176 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
177
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
178 ###############################################################################
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
179
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
180 sub http_fake_daemon {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
181 my $server = IO::Socket::INET->new(
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
182 Proto => 'tcp',
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
183 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
184 Listen => 5,
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
185 Reuse => 1
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
186 )
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
187 or die "Can't create listening socket: $!\n";
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 my $num = 0;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
190 my $uri = '';
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
191
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
192 while (my $client = $server->accept()) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
193 $client->autoflush(1);
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
194
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
195 while (<$client>) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
196 if (/GET (.*) HTTP/ && $1 ne $uri) {
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
197 $uri = $1;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
198 $num = 0;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
199 }
212
a7cc4371f4ad Tests: whitespace fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 191
diff changeset
200
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
201 $uri = $1 if /GET (.*) HTTP/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
202 last if /^\x0d?\x0a?$/;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
203 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
204
213
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
205 next unless $uri;
4ac0807cc3cf Tests: eliminate race in proxy_cache_lock.t startup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 212
diff changeset
206
184
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
207 sleep(1);
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 $num++;
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
210 print $client <<"EOF";
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
211 HTTP/1.1 200 OK
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
212 Cache-Control: max-age=300
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
213 Connection: close
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
214
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
215 request $num
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
216 EOF
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
217 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
218 }
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
219
f432f11a3b12 Tests: proxy cache lock tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
220 ###############################################################################