Mercurial > hg > ngx_http_gunzip_filter_module
comparison t/gunzip-memcached.t @ 6:45e54370c2d0
Gunzip: add tests for replies from memcached with gzip.
This uses memcached_gzip_flag directive (the one not yet added into official
nginx). Tests are skipped if it's not available.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 28 Dec 2009 03:58:57 +0300 |
parents | |
children | 9158103f8571 |
comparison
equal
deleted
inserted
replaced
5:d8e85fd12fab | 6:45e54370c2d0 |
---|---|
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 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081'); | |
61 | |
62 eval { | |
63 open OLDERR, ">&", \*STDERR; close STDERR; | |
64 $t->run(); | |
65 open STDERR, ">&", \*OLDERR; | |
66 }; | |
67 plan(skip_all => 'no memcached_gzip_flag') if $@; | |
68 | |
69 $t->plan(2); | |
70 | |
71 $t->waitforsocket('127.0.0.1:8081') | |
72 or die "Can't start memcached"; | |
73 | |
74 # Put compressed value into memcached. This requires compress_threshold to be | |
75 # set and compressed value to be at least 20% less than original one. | |
76 | |
77 my $memd = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ], | |
78 compress_threshold => 1); | |
79 $memd->set('/', 'TEST' x 10) | |
80 or die "can't put value into memcached: $!"; | |
81 | |
82 ############################################################################### | |
83 | |
84 http_gzip_like(http_gzip_request('/'), qr/TEST/, 'memcached response gzipped'); | |
85 like(http_get('/'), qr/TEST/, 'memcached response gunzipped'); | |
86 | |
87 ############################################################################### |