annotate upstream_hash_memcached.t @ 605:a77f19282f63

Tests: switched to using headers to test variables in userid.t. Tests might behave incorrectly due to the delay in writing to log. Made tests stricter for different endianness. While here, improved style.
author Andrey Zelenkov <zelenkov@nginx.com>
date Thu, 11 Jun 2015 20:56:19 +0300
parents c0b4ae82fd9d
children 0597ca82c26a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for upstream hash balancer module distribution consistency
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # with Cache::Memcached and Cache::Memcached::Fast.
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 ###############################################################################
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use warnings;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use strict;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Test::More;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
582
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
16 use Config;
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
17
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 BEGIN { use FindBin; chdir($FindBin::Bin); }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use lib 'lib';
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 use Test::Nginx;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 ###############################################################################
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDERR; $| = 1;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 select STDOUT; $| = 1;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 eval { require Cache::Memcached; };
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 plan(skip_all => 'Cache::Memcached not installed') if $@;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 eval { require Cache::Memcached::Fast; };
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 plan(skip_all => 'Cache::Memcached::Fast not installed') if $@;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 my $t = Test::Nginx->new()->has(qw/http rewrite memcached upstream_hash/)
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
34 ->has_daemon('memcached')->plan(4);
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
35
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
36 $t->write_file_expand('nginx.conf', <<'EOF');
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 %%TEST_GLOBALS%%
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 daemon off;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 events {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 http {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 %%TEST_GLOBALS_HTTP%%
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 upstream memd {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 hash $arg_a;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 server 127.0.0.1:8081;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server 127.0.0.1:8082;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server 127.0.0.1:8083;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 upstream memd_c {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 hash $arg_a consistent;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 server 127.0.0.1:8081;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 server 127.0.0.1:8082;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 server 127.0.0.1:8083;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 upstream memd_w {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 hash $arg_a;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 server 127.0.0.1:8081 weight=2;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 server 127.0.0.1:8082 weight=3;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 server 127.0.0.1:8083;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 upstream memd_cw {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 hash $arg_a consistent;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 server 127.0.0.1:8081 weight=2;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 server 127.0.0.1:8082 weight=3;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 server 127.0.0.1:8083;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 server {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 listen 127.0.0.1:8080;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 server_name localhost;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 set $memcached_key $arg_a;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 location / {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 memcached_pass memd;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 location /c {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 memcached_pass memd_c;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 location /w {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 memcached_pass memd_w;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 location /cw {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 memcached_pass memd_cw;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 EOF
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 my $memhelp = `memcached -h`;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 my @memopts = ();
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 if ($memhelp =~ /repcached/) {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 # repcached patch adds additional listen socket
412
995f3476202e Tests: unbreak upsream hash tests with repcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 411
diff changeset
104 push @memopts, '-X', '0';
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 if ($memhelp =~ /-U/) {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 # UDP port is on by default in memcached 1.2.7+
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 push @memopts, '-U', '0';
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts);
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082', @memopts);
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8083', @memopts);
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
114 $t->run();
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 $t->waitforsocket('127.0.0.1:8081') or die "Can't start memcached";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 $t->waitforsocket('127.0.0.1:8082') or die "Can't start memcached";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 $t->waitforsocket('127.0.0.1:8083') or die "Can't start memcached";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 ###############################################################################
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
587
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
122 my $memd1 = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ],
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
123 connect_timeout => 1.0);
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
124 my $memd2 = Cache::Memcached->new(servers => [ '127.0.0.1:8082' ],
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
125 connect_timeout => 1.0);
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
126 my $memd3 = Cache::Memcached->new(servers => [ '127.0.0.1:8083' ],
c0b4ae82fd9d Tests: adjusted memcached test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 582
diff changeset
127 connect_timeout => 1.0);
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 for my $i (1 .. 20) {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 $memd1->set($i, '8081') or die "can't put value into memcached: $!";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 $memd2->set($i, '8082') or die "can't put value into memcached: $!";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 $memd3->set($i, '8083') or die "can't put value into memcached: $!";
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 my $memd = new Cache::Memcached(servers =>
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 [ '127.0.0.1:8081', '127.0.0.1:8082', '127.0.0.1:8083' ]);
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 is_deeply(ngx('/'), mem($memd), 'cache::memcached');
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 $memd = new Cache::Memcached::Fast({ ketama_points => 160, servers =>
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 [ '127.0.0.1:8081', '127.0.0.1:8082', '127.0.0.1:8083'] });
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
582
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
143 TODO: {
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
144 local $TODO = 'not yet' unless $Config{byteorder} eq '12345678'
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
145 or $t->has_version('1.9.1');
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
146
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 is_deeply(ngx('/c'), mem($memd), 'cache::memcached::fast');
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
582
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
149 }
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
150
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 $memd = new Cache::Memcached(servers => [
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 [ '127.0.0.1:8081', 2 ],
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 [ '127.0.0.1:8082', 3 ],
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 [ '127.0.0.1:8083', 1 ]]);
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 is_deeply(ngx('/w'), mem($memd), 'cache::memcached weight');
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 $memd = new Cache::Memcached::Fast({ ketama_points => 160, servers => [
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 { address => '127.0.0.1:8081', weight => 2 },
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 { address => '127.0.0.1:8082', weight => 3 },
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 { address => '127.0.0.1:8083', weight => 1 }] });
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
582
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
163 TODO: {
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
164 local $TODO = 'not yet' unless $Config{byteorder} eq '12345678'
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
165 or $t->has_version('1.9.1');
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
166
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 is_deeply(ngx('/cw'), mem($memd), 'cache::memcached::fast weight');
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168
582
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
169 }
dc97097100a5 Tests: upstream_hash_memcached.t TODOs on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
170
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 ###############################################################################
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 sub ngx {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 my ($uri) = @_;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 [ map { http_get("/$uri?a=$_") =~ /^(\d+)/ms && $1; } (1 .. 20) ];
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 sub mem {
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 my ($memd) = @_;
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 [ map { $memd->get($_); } (1 .. 20) ];
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 }
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 ###############################################################################