Mercurial > hg > ngx_http_upstream_keepalive
annotate t/memcached-keepalive.t @ 42:c53e018dbcf5
Keepalive: do not reject connections with ready flag set.
Instead, call read event handler explicitly to test if there are actually
any unexpected data. This fixes unbuffered proxy connections not being
cached with epoll and rtsig event methods.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 08 Sep 2011 17:12:07 +0400 |
parents | 2ee28064a04a |
children | 489c5d4318ff |
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; }; |
13
181a487581b7
Keepalive: fix typo in tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
12
diff
changeset
|
21 plan(skip_all => 'Cache::Memcached not installed') if $@; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
24
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(17) |
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 |
20 | 26 %%TEST_GLOBALS%% |
27 | |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 daemon off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 events { |
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 { |
20 | 34 %%TEST_GLOBALS_HTTP%% |
1
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 upstream memd { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server 127.0.0.1:8081; |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
38 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
39 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
40 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
41 upstream memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
42 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
43 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
44 keepalive 1 single; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
45 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
46 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
47 upstream memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
48 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
49 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
50 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
51 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
52 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
53 upstream memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
54 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
55 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
56 keepalive 10; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 server { |
20 | 60 listen 127.0.0.1:8080; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 server_name localhost; |
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 location / { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 memcached_pass memd; |
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 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 location /next { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 memcached_next_upstream not_found; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 } |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
73 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
74 location /memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
75 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
76 memcached_pass memd2; |
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 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
79 location /memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
80 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
81 memcached_pass memd3; |
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 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
84 location /memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
85 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
86 memcached_pass memd4; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
87 } |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 EOF |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
93 my $memhelp = `memcached -h`; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
94 my @memopts1 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
95 my @memopts2 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
96 |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
97 if ($memhelp =~ /repcached/) { |
12
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 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
101 push @memopts1, '-X', '8091'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
102 push @memopts2, '-X', '8092'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
103 } |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
104 if ($memhelp =~ /-U/) { |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
105 # UDP ports no longer off by default in memcached 1.2.7+ |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
106 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
107 push @memopts1, '-U', '0'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
108 push @memopts2, '-U', '0'; |
12
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 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
111 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts1); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
112 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082', @memopts2); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
113 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 $t->run(); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
116 $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
|
117 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
|
118 $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
|
119 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
|
120 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 ############################################################################### |
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 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
|
124 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
|
125 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
126 $memd1->set('/', 'SEE-THIS'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
127 $memd2->set('/', 'SEE-THIS'); |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
128 $memd1->set('/big', 'X' x 1000000); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
129 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
130 my $total = $memd1->stats()->{total}->{total_connections}; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 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
|
134 like(http_get('/next'), qr/404/, |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 'keepalive not found with memcached_next_upstream'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
140 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
|
141 'only one connection used'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
142 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
143 # 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
|
144 # 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
|
145 # connections. Check if we really do close them. |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
146 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
147 $total = $memd1->stats()->{total}->{total_connections}; |
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 unlike(http_head('/'), qr/SEE-THIS/, 'head request'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
150 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
|
151 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
152 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
153 'head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
154 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
155 $total = $memd1->stats()->{total}->{total_connections}; |
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 unlike(http_head('/big'), qr/XXX/, 'big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
158 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
|
159 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
160 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
161 'big head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
162 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
163 # 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
|
164 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
165 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
166 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
167 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
168 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
169 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
170 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
171 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
172 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
173 $memd2->stats()->{total}->{total_connections}, $total + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
174 '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
|
175 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
176 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
177 $memd2->stats()->{total}->{total_connections}; |
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 # 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
|
180 # 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
|
181 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
182 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
183 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
184 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
185 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
186 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
187 $memd2->stats()->{total}->{total_connections}, $total + 3, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
188 '3 connections should be established'); |
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 # 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
|
191 # 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
|
192 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
193 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
194 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
195 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
196 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
197 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
198 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
199 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
200 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
201 $memd2->stats()->{total}->{total_connections}, $total + 2, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
202 'connection per backend'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 |
24
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
204 $t->stop(); |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
205 |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
206 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
207 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
208 ############################################################################### |