Skip to content
Newer
Older
100644 100 lines (70 sloc) 2.11 KB
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for memcached backend with fake daemon.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13 use Socket qw/ CRLF /;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
d62fd96 @mdounin Tests: add test for memcached parsing problem as fixed in 0.6.14.
mdounin authored Feb 19, 2010
25 my $t = Test::Nginx->new()->has(qw/http rewrite memcached ssi/)->plan(3)
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 master_process off;
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 location / {
44 set $memcached_key $uri;
45 memcached_pass 127.0.0.1:8081;
46 }
d62fd96 @mdounin Tests: add test for memcached parsing problem as fixed in 0.6.14.
mdounin authored Feb 19, 2010
47
48 location /ssi {
49 default_type text/html;
50 ssi on;
51 }
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
52 }
53 }
54
55 EOF
56
d62fd96 @mdounin Tests: add test for memcached parsing problem as fixed in 0.6.14.
mdounin authored Feb 19, 2010
57 $t->write_file('ssi.html', '<!--#include virtual="/" set="blah" -->blah: <!--#echo var="blah" -->');
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
58 $t->run_daemon(\&memcached_fake_daemon);
59 $t->run();
60
61 ###############################################################################
62
63 like(http_get('/'), qr/SEE-THIS/, 'memcached split trailer');
64
d62fd96 @mdounin Tests: add test for memcached parsing problem as fixed in 0.6.14.
mdounin authored Feb 19, 2010
65 like(http_get('/ssi.html'), qr/SEE-THIS/, 'memcached ssi var');
66
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
67 like(`grep -F '[error]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no error');
68
69 ###############################################################################
70
71 sub memcached_fake_daemon {
72 my $server = IO::Socket::INET->new(
73 Proto => 'tcp',
74 LocalAddr => '127.0.0.1:8081',
75 Listen => 5,
76 Reuse => 1
77 )
78 or die "Can't create listening socket: $!\n";
79
80 while (my $client = $server->accept()) {
81 $client->autoflush(1);
82
83 while (<$client>) {
84 last if (/\x0d\x0a$/);
85 }
86
87 print $client 'VALUE / 0 8' . CRLF;
d62fd96 @mdounin Tests: add test for memcached parsing problem as fixed in 0.6.14.
mdounin authored Feb 19, 2010
88 print $client 'SEE-TH';
89 select(undef, undef, undef, 0.1);
90 print $client 'IS';
d06c295 @mdounin Tests: memcached split trailer test.
mdounin authored Feb 16, 2010
91 select(undef, undef, undef, 0.1);
92 print $client CRLF . 'EN';
93 select(undef, undef, undef, 0.1);
94 print $client 'D' . CRLF;
95 close $client;
96 }
97 }
98
99 ###############################################################################
Something went wrong with that request. Please try again.