Mercurial > hg > nginx-tests
annotate memcached.t @ 388:3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 07 Apr 2014 20:25:40 +0400 |
parents | 6a0d934950bc |
children | d5bf5942a8b2 |
rev | line source |
---|---|
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for memcached backend. |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require Cache::Memcached; }; |
54 | 25 plan(skip_all => 'Cache::Memcached not installed') if $@; |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http rewrite memcached/) |
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
28 ->has_daemon('memcached')->plan(4) |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
84
diff
changeset
|
31 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
84
diff
changeset
|
32 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
33 daemon off; |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 } |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
84
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
34
diff
changeset
|
40 |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
41
diff
changeset
|
42 listen 127.0.0.1:8080; |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 set $memcached_key $uri; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 memcached_pass 127.0.0.1:8081; |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 } |
34
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
49 |
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
50 location /next { |
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
51 set $memcached_key $uri; |
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
52 memcached_next_upstream not_found; |
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
53 memcached_pass 127.0.0.1:8081; |
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
54 } |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 EOF |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
122
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
60 my $memhelp = `memcached -h`; |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
61 my @memopts = (); |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
62 |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
63 if ($memhelp =~ /repcached/) { |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
64 # repcached patch adds additional listen socket |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
65 push @memopts, '-X', '8082'; |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
66 } |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
67 if ($memhelp =~ /-U/) { |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
68 # UDP port is on by default in memcached 1.2.7+ |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
69 push @memopts, '-U', '0'; |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
70 } |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
71 |
01e86a067f05
Tests: fix tests for repcached and memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
72 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts); |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 $t->run(); |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
50
b494fe5b12d1
Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
45
diff
changeset
|
75 $t->waitforsocket('127.0.0.1:8081') |
b494fe5b12d1
Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
45
diff
changeset
|
76 or die "Can't start memcached"; |
b494fe5b12d1
Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
45
diff
changeset
|
77 |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 ############################################################################### |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 my $memd = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]); |
84
e48ac6e9a390
Tests: die if we failed to put test data into memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
81 $memd->set('/', 'SEE-THIS') |
e48ac6e9a390
Tests: die if we failed to put test data into memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
82 or die "can't put value into memcached: $!"; |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 like(http_get('/'), qr/SEE-THIS/, 'memcached request'); |
61
74f276d0fca1
Tests: mark memcached notfound test as TODO, broken for too long.
Maxim Dounin <mdounin@mdounin.ru>
parents:
54
diff
changeset
|
85 |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 like(http_get('/notfound'), qr/404/, 'memcached not found'); |
61
74f276d0fca1
Tests: mark memcached notfound test as TODO, broken for too long.
Maxim Dounin <mdounin@mdounin.ru>
parents:
54
diff
changeset
|
87 |
34
689174c36e94
Tests: memcached in 0.7.19 works only with next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
29
diff
changeset
|
88 like(http_get('/next'), qr/404/, 'not found with memcached_next_upstream'); |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
36
diff
changeset
|
90 unlike(http_head('/'), qr/SEE-THIS/, 'memcached no data in HEAD'); |
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
36
diff
changeset
|
91 |
29
71ea39729fa0
Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 ############################################################################### |