Mercurial > hg > nginx-tests
annotate memcached_fake.t @ 1995:d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Both "cat" and "grep" might not be available on Windows. Instead,
$t->read_file() is used, as it is already used in other places. To
simplify checking logs as previously done with "grep", $t->grep_file()
helper function is introduced.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Aug 2024 05:18:51 +0300 |
parents | 4442767118e0 |
children |
rev | line source |
---|---|
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for memcached backend with fake daemon. |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Socket qw/ CRLF /; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ############################################################################### |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
128
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite memcached ssi/)->plan(3) |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
30 daemon off; |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:8080; |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server_name localhost; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 location / { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 set $memcached_key $uri; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 memcached_pass 127.0.0.1:8081; |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 } |
128
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
46 |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
47 location /ssi { |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
48 default_type text/html; |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
49 ssi on; |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
50 } |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 EOF |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
1293
4442767118e0
Tests: wrap long line.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1009
diff
changeset
|
56 $t->write_file('ssi.html', |
4442767118e0
Tests: wrap long line.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1009
diff
changeset
|
57 '<!--#include virtual="/" set="blah" -->' . |
4442767118e0
Tests: wrap long line.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1009
diff
changeset
|
58 'blah: <!--#echo var="blah" -->'); |
4442767118e0
Tests: wrap long line.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1009
diff
changeset
|
59 |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 $t->run_daemon(\&memcached_fake_daemon); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $t->run(); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 $t->waitforsocket('127.0.0.1:' . port(8081)) |
267
9cd1a8dd47fc
Tests: eliminate race in memcached_fake.t startup.
Valentin Bartenev <vbart@nginx.com>
parents:
257
diff
changeset
|
64 or die "Can't start fake memcached"; |
9cd1a8dd47fc
Tests: eliminate race in memcached_fake.t startup.
Valentin Bartenev <vbart@nginx.com>
parents:
257
diff
changeset
|
65 |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 ############################################################################### |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 like(http_get('/'), qr/SEE-THIS/, 'memcached split trailer'); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
128
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
70 like(http_get('/ssi.html'), qr/SEE-THIS/, 'memcached ssi var'); |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
71 |
1995
d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1293
diff
changeset
|
72 is($t->grep_file('error.log', '[error]'), '', 'no errors'); |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 ############################################################################### |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 sub memcached_fake_daemon { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 my $server = IO::Socket::INET->new( |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 LocalAddr => '127.0.0.1:' . port(8081), |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 Listen => 5, |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 Reuse => 1 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 ) |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 or die "Can't create listening socket: $!\n"; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
267
9cd1a8dd47fc
Tests: eliminate race in memcached_fake.t startup.
Valentin Bartenev <vbart@nginx.com>
parents:
257
diff
changeset
|
85 local $SIG{PIPE} = 'IGNORE'; |
9cd1a8dd47fc
Tests: eliminate race in memcached_fake.t startup.
Valentin Bartenev <vbart@nginx.com>
parents:
257
diff
changeset
|
86 |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 while (my $client = $server->accept()) { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 $client->autoflush(1); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 while (<$client>) { |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 last if (/\x0d\x0a$/); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 print $client 'VALUE / 0 8' . CRLF; |
128
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
95 print $client 'SEE-TH'; |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
96 select(undef, undef, undef, 0.1); |
25047dc6ae9b
Tests: add test for memcached parsing problem as fixed in 0.6.14.
Maxim Dounin <mdounin@mdounin.ru>
parents:
127
diff
changeset
|
97 print $client 'IS'; |
127
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 select(undef, undef, undef, 0.1); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 print $client CRLF . 'EN'; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 select(undef, undef, undef, 0.1); |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 print $client 'D' . CRLF; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 close $client; |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 } |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
2bf0c4c80aa7
Tests: memcached split trailer test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 ############################################################################### |