annotate memcached_keepalive.t @ 572:ca54b445d982

Tests: masked nginx bug in proxy next upstream. When iterating through several next upstreams per a worker cycle, a previously reported event about upstream connection error may be improperly applied to the next upstream, thus leading to the invalid connection error. E.g., in kqueue, where the problem is visible, this is caused by "ev->instance" that does not tolerate more than one next upstream at once, and kevents placed on the kqueue separately for read and write events. The change is to limit test case to the only one next upstream.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 14 May 2015 11:54:24 +0300
parents 1a73389a19c4
children c0b4ae82fd9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Test for memcached with keepalive.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 eval { require Cache::Memcached; };
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 plan(skip_all => 'Cache::Memcached not installed') if $@;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
275
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http memcached upstream_keepalive rewrite/)
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 250
diff changeset
28 ->has_daemon('memcached')->plan(16)
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 ->write_file_expand('nginx.conf', <<'EOF');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 %%TEST_GLOBALS%%
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 daemon off;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 events {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 http {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 upstream memd {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 server 127.0.0.1:8081;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 keepalive 1;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 upstream memd3 {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 server 127.0.0.1:8081;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 server 127.0.0.1:8082;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 keepalive 1;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 upstream memd4 {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 server 127.0.0.1:8081;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 server 127.0.0.1:8082;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 keepalive 10;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 server {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 listen 127.0.0.1:8080;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 server_name localhost;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 location / {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 set $memcached_key $uri;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 memcached_pass memd;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 location /next {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 set $memcached_key $uri;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 memcached_next_upstream not_found;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 memcached_pass memd;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 location /memd3 {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 set $memcached_key "/";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 memcached_pass memd3;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 location /memd4 {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 set $memcached_key "/";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 memcached_pass memd4;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 EOF
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 my $memhelp = `memcached -h`;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 my @memopts1 = ();
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 my @memopts2 = ();
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 if ($memhelp =~ /repcached/) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 # repcached patches adds additional listen socket memcached
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 # that should be different too
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 push @memopts1, '-X', '8091';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 push @memopts2, '-X', '8092';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98 if ($memhelp =~ /-U/) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 # UDP ports no longer off by default in memcached 1.2.7+
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 push @memopts1, '-U', '0';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 push @memopts2, '-U', '0';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 }
513
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
104 if ($memhelp =~ /-t/) {
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
105 # for connection stats consistency in threaded memcached 1.3+
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
106
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
107 push @memopts1, '-t', '1';
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
108 push @memopts2, '-t', '1';
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 491
diff changeset
109 }
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts1);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082', @memopts2);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 $t->run();
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116 $t->waitforsocket('127.0.0.1:8081')
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 or die "Unable to start memcached";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 $t->waitforsocket('127.0.0.1:8082')
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 or die "Unable to start second memcached";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 ###############################################################################
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
122
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
123 my $memd1 = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 my $memd2 = Cache::Memcached->new(servers => [ '127.0.0.1:8082' ]);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126 $memd1->set('/', 'SEE-THIS');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127 $memd2->set('/', 'SEE-THIS');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128 $memd1->set('/big', 'X' x 1000000);
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
130 my $total = $memd1->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
131
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request');
491
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
133 like(http_get('/notfound'), qr/ 404 /, 'keepalive memcached not found');
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
134 like(http_get('/next'), qr/ 404 /,
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
135 'keepalive not found with memcached_next_upstream');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
136 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
137 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
138 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
139
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
140 is($memd1->stats()->{total}->{total_connections}, $total + 1,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
141 'only one connection used');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
142
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
143 # Since nginx doesn't read all data from connection in some situations (head
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
144 # requests, post_action, errors writing to client) we have to close such
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
145 # connections. Check if we really do close them.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
146
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
147 $total = $memd1->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
148
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
149 unlike(http_head('/'), qr/SEE-THIS/, 'head request');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
150 like(http_get('/'), qr/SEE-THIS/, 'get after head');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
151
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
152 is($memd1->stats()->{total}->{total_connections}, $total + 1,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
153 'head request closes connection');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
154
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
155 $total = $memd1->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
156
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
157 unlike(http_head('/big'), qr/XXX/, 'big head');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
158 like(http_get('/'), qr/SEE-THIS/, 'get after big head');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
159
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
160 is($memd1->stats()->{total}->{total_connections}, $total + 1,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
161 'big head request closes connection');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
162
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
163 # two backends with maximum number of cached connections set to 1,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
164 # should establish new connection on each request
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
165
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
166 $total = $memd1->stats()->{total}->{total_connections} +
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
167 $memd2->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
168
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
169 http_get('/memd3');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
170 http_get('/memd3');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
171 http_get('/memd3');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
172
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
173 is($memd1->stats()->{total}->{total_connections} +
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
174 $memd2->stats()->{total}->{total_connections}, $total + 3,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
175 '3 connections should be established');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
176
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
177 # two backends with maximum number of cached connections set to 10,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
178 # should establish only two connections (1 per backend)
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
179
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
180 $total = $memd1->stats()->{total}->{total_connections} +
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
181 $memd2->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
182
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
183 http_get('/memd4');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
184 http_get('/memd4');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
185 http_get('/memd4');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
186
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
187 is($memd1->stats()->{total}->{total_connections} +
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
188 $memd2->stats()->{total}->{total_connections}, $total + 2,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
189 'connection per backend');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
190
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
191 $t->stop();
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
192
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
193 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
194
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
195 ###############################################################################