Mercurial > hg > ngx_http_upstream_keepalive
annotate t/memcached-keepalive.t @ 12:067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
And add waitforsocket() calls to avoid startup races.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 Nov 2008 22:23:21 +0300 |
parents | 15530a464dba |
children | 181a487581b7 |
rev | line source |
---|---|
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for memcached with keepalive. |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Test::Nginx; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 select STDERR; $| = 1; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 select STDOUT; $| = 1; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 eval { require Cache::Memcached; }; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 plain(skip_all => 'Cache::Memcached not installed') if $@; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(16) |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 ->write_file_expand('nginx.conf', <<'EOF'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 master_process off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 daemon off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 events { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 worker_connections 1024; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 http { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 access_log off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 client_body_temp_path %%TESTDIR%%/client_body_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 proxy_temp_path %%TESTDIR%%/proxy_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 upstream memd { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server 127.0.0.1:8081; |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
42 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
43 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
44 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
45 upstream memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
46 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
47 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
48 keepalive 1 single; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
49 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
50 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
51 upstream memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
52 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
53 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
54 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
55 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
56 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
57 upstream memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
58 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
59 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
60 keepalive 10; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 server { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 listen localhost:8080; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 server_name localhost; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 location / { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 location /next { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 memcached_next_upstream not_found; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 } |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
77 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
78 location /memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
79 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
80 memcached_pass memd2; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
81 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
82 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
83 location /memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
84 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
85 memcached_pass memd3; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
86 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
87 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
88 location /memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
89 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
90 memcached_pass memd4; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
91 } |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 EOF |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
97 if (`memcached -h` =~ /repcached/) { |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
98 # repcached patches adds additional listen socket memcached |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
99 # that should be different too |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
100 |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
101 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
102 '-X', '8091'); |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
103 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082', |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
104 '-X', '8092'); |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
105 |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
106 } else { |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
107 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081'); |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
108 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082'); |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
109 } |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
110 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 $t->run(); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
113 $t->waitforsocket('127.0.0.1:8081') |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
114 or die "Unable to start memcached"; |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
115 $t->waitforsocket('127.0.0.1:8082') |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
116 or die "Unable to start second memcached"; |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
117 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
120 my $memd1 = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
121 my $memd2 = Cache::Memcached->new(servers => [ '127.0.0.1:8082' ]); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
123 $memd1->set('/', 'SEE-THIS'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
124 $memd2->set('/', 'SEE-THIS'); |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
125 $memd1->set('/big', 'X' x 1000000); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
126 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
127 my $total = $memd1->stats()->{total}->{total_connections}; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 like(http_get('/notfound'), qr/404/, 'keepalive memcached not found'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 like(http_get('/next'), qr/404/, |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 'keepalive not found with memcached_next_upstream'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
137 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
138 'only one connection used'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
139 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
140 # Since nginx doesn't read all data from connection in some situations (head |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
141 # requests, post_action, errors writing to client) we have to close such |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
142 # connections. Check if we really do close them. |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
143 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
144 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
145 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
146 unlike(http_head('/'), qr/SEE-THIS/, 'head request'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
147 like(http_get('/'), qr/SEE-THIS/, 'get after head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
148 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
149 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
150 'head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
151 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
152 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
153 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
154 unlike(http_head('/big'), qr/XXX/, 'big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
155 like(http_get('/'), qr/SEE-THIS/, 'get after big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
156 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
157 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
158 'big head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
159 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
160 # two backends with 'single' option - should establish only one connection |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
161 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
162 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
163 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
164 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
165 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
166 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
167 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
168 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
169 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
170 $memd2->stats()->{total}->{total_connections}, $total + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
171 'only one connection with two backends and single'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
172 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
173 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
174 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
175 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
176 # two backends without 'single' option and maximum number of cached |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
177 # connections set to 1 - should establish new connection on each request |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
178 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
179 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
180 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
181 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
182 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
183 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
184 $memd2->stats()->{total}->{total_connections}, $total + 3, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
185 '3 connections should be established'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
186 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
187 # two backends without 'single' option and maximum number of cached |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
188 # connections set to 10 - should establish only two connections (1 per backend) |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
189 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
190 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
191 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
192 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
193 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
194 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
195 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
196 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
197 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
198 $memd2->stats()->{total}->{total_connections}, $total + 2, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
199 'connection per backend'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 ############################################################################### |