Mercurial > hg > nginx-tests
annotate memcached_keepalive_stale.t @ 257:2cb970dda24b
Tests: revert unintentional memcached_fake.t change.
It was used for local testing and accidentally slipped into 0cc5269bc62c.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 30 Jan 2013 15:20:51 +0400 |
parents | 0c9f15938545 |
children | 6cbcfb4ef7ee |
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 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(2) |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 daemon off; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 worker_processes 2; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 events { |
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 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 http { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 upstream memd { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server 127.0.0.1:8081; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 keepalive 1; |
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 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 server { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 listen 127.0.0.1:8080 sndbuf=32k; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 server_name localhost; |
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 location / { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 set $memcached_key $uri; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 memcached_pass memd; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
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 EOF |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 my $memhelp = `memcached -h`; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 my @memopts1 = (); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 if ($memhelp =~ /repcached/) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 # repcached patches adds additional listen socket memcached |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 # that should be different too |
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 push @memopts1, '-X', '8091'; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 if ($memhelp =~ /-U/) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 # 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
|
71 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 push @memopts1, '-U', '0'; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 $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
|
76 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 $t->run(); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 $t->waitforsocket('127.0.0.1:8081') |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 or die "Unable to start memcached"; |
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 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
|
85 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 # 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
|
87 # for just saved upstream connection without any data available for |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 # read. We shouldn't close upstream connection in such situation. |
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 # 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
|
91 # 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
|
92 # events. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 # |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 # 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
|
95 # 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
|
96 # 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
|
97 # buffer. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 # |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 # 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
|
100 # 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
|
101 # events at least on FreeBSD testbed here. |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 $memd1->set('/big', 'X' x 20480); |
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 my $total = $memd1->stats()->{total}->{total_connections}; |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 for (1 .. 100) { |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 http_get('/big'); |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 } |
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 cmp_ok($memd1->stats()->{total}->{total_connections}, '<=', $total + 2, |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 'only one connection per worker used'); |
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->stop(); |
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 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
|
117 |
0c9f15938545
Tests: upstream keepalive tests imported.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 ############################################################################### |