Mercurial > hg > nginx-tests
comparison memcached_fake.t @ 148:b714d6df958c
Tests: rename some tests for better sorting.
Use underscore instead of dash. Addtionally, rename some tests to better
match "module" + "details" scheme used: use "http_" prefix for http core
module tests, use "mail_" prefix for mail module tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 04 Mar 2011 16:07:15 +0300 |
parents | memcached-fake.t@e7371b38cd2c |
children | c0ae29632905 |
comparison
equal
deleted
inserted
replaced
147:fd865ada95c8 | 148:b714d6df958c |
---|---|
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 | |
25 my $t = Test::Nginx->new()->has(qw/http rewrite memcached ssi/)->plan(3) | |
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 } | |
47 | |
48 location /ssi { | |
49 default_type text/html; | |
50 ssi on; | |
51 } | |
52 } | |
53 } | |
54 | |
55 EOF | |
56 | |
57 $t->write_file('ssi.html', '<!--#include virtual="/" set="blah" -->blah: <!--#echo var="blah" -->'); | |
58 $t->run_daemon(\&memcached_fake_daemon); | |
59 $t->run(); | |
60 | |
61 ############################################################################### | |
62 | |
63 like(http_get('/'), qr/SEE-THIS/, 'memcached split trailer'); | |
64 | |
65 like(http_get('/ssi.html'), qr/SEE-THIS/, 'memcached ssi var'); | |
66 | |
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; | |
88 print $client 'SEE-TH'; | |
89 select(undef, undef, undef, 0.1); | |
90 print $client 'IS'; | |
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 ############################################################################### |