annotate memcached_keepalive_stale.t @ 540:481d705b8610

Tests: SSL support in mail backends. Socket is now embedded into every mail module. Socket methods are wrapped where appropriate. The new "SSL" extra flag specifies to accept connection over SSL.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 03 Apr 2015 00:11:38 +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 stale events handling in upstream 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(2)
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 worker_processes 2;
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 events {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40 http {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 %%TEST_GLOBALS_HTTP%%
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 upstream memd {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 server 127.0.0.1:8081;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 keepalive 1;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 server {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 listen 127.0.0.1:8080 sndbuf=32k;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 server_name localhost;
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 location / {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 set $memcached_key $uri;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 memcached_pass memd;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 }
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
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 EOF
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 my $memhelp = `memcached -h`;
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 my @memopts1 = ();
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 if ($memhelp =~ /repcached/) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 # repcached patches adds additional listen socket memcached
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 # that should be different too
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 push @memopts1, '-X', '8091';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 }
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 if ($memhelp =~ /-U/) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 # 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
72
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 push @memopts1, '-U', '0';
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 }
513
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
75 if ($memhelp =~ /-t/) {
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
76 # for connection stats consistency in threaded memcached 1.3+
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
77
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
78 push @memopts1, '-t', '1';
1a73389a19c4 Tests: fixed tests with multi-threaded memcached.
Sergey Kandaurov <pluknet@nginx.com>
parents: 275
diff changeset
79 }
250
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 $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
82
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 $t->run();
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 $t->waitforsocket('127.0.0.1:8081')
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86 or die "Unable to start memcached";
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 ###############################################################################
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90 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
91
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 # It's possible that stale events occur, i.e. read event handler called
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 # for just saved upstream connection without any data available for
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 # read. We shouldn't close upstream connection in such situation.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 #
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 # This happens due to reading from upstream connection on downstream write
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 # events. More likely to happen with multiple workers due to use of posted
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98 # events.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 #
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 # Stale event may only happen if reading response from upstream requires
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 # entering event loop, i.e. response should be big enough. On the other
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 # hand, it is less likely to occur with full client's connection output
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 # buffer.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104 #
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 # We use here 2 workers, 20k response and set output buffer on clients
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106 # connection to 32k. This allows more or less reliably reproduce stale
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 # events at least on FreeBSD testbed here.
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109 $memd1->set('/big', 'X' x 20480);
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 my $total = $memd1->stats()->{total}->{total_connections};
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113 for (1 .. 100) {
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 http_get('/big');
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
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 cmp_ok($memd1->stats()->{total}->{total_connections}, '<=', $total + 2,
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 'only one connection per worker used');
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120 $t->stop();
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 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
123
0c9f15938545 Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 ###############################################################################