comparison t/gunzip_memcached.t @ 20:1adc6718cc05 draft

Gunzip: rename tests for better sorting.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 07 Sep 2012 19:27:41 +0400
parents t/gunzip-memcached.t@9158103f8571
children c0301992025a
comparison
equal deleted inserted replaced
19:9d299b9f877b 20:1adc6718cc05
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for gunzip filter module with memcached.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx qw/ :DEFAULT :gzip /;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 eval { require Cache::Memcached; };
25 plan(skip_all => 'Cache::Memcached not installed') if $@;
26
27 eval { require IO::Compress::Gzip; };
28 plan(skip_all => "IO::Compress::Gzip not found") if $@;
29
30 my $t = Test::Nginx->new()->has(qw/http memcached/)->has_daemon('memcached')
31 ->write_file_expand('nginx.conf', <<'EOF');
32
33 %%TEST_GLOBALS%%
34
35 master_process off;
36 daemon off;
37
38 events {
39 }
40
41 http {
42 %%TEST_GLOBALS_HTTP%%
43
44 server {
45 listen 127.0.0.1:8080;
46 server_name localhost;
47
48 gunzip on;
49
50 location / {
51 set $memcached_key $uri;
52 memcached_pass 127.0.0.1:8081;
53 memcached_gzip_flag 2;
54 }
55 }
56 }
57
58 EOF
59
60 my $memhelp = `memcached -h`;
61 my @memopts = ();
62
63 if ($memhelp =~ /repcached/) {
64 # repcached patch adds additional listen socket
65 push @memopts, '-X', '8082';
66 }
67 if ($memhelp =~ /-U/) {
68 # UDP port is on by default in memcached 1.2.7+
69 push @memopts, '-U', '0';
70 }
71
72 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts);
73
74 eval {
75 open OLDERR, ">&", \*STDERR; close STDERR;
76 $t->run();
77 open STDERR, ">&", \*OLDERR;
78 };
79 plan(skip_all => 'no memcached_gzip_flag') if $@;
80
81 $t->plan(2);
82
83 $t->waitforsocket('127.0.0.1:8081')
84 or die "Can't start memcached";
85
86 # Put compressed value into memcached. This requires compress_threshold to be
87 # set and compressed value to be at least 20% less than original one.
88
89 my $memd = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ],
90 compress_threshold => 1);
91 $memd->set('/', 'TEST' x 10)
92 or die "can't put value into memcached: $!";
93
94 ###############################################################################
95
96 http_gzip_like(http_gzip_request('/'), qr/TEST/, 'memcached response gzipped');
97 like(http_get('/'), qr/TEST/, 'memcached response gunzipped');
98
99 ###############################################################################