comparison fastcgi_cache.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 fastcgi-cache.t@df9a573fde22
children c0ae29632905
comparison
equal deleted inserted replaced
147:fd865ada95c8 148:b714d6df958c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for fastcgi backend with cache.
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;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 eval { require FCGI; };
25 plan(skip_all => 'FCGI not installed') if $@;
26
27 my $t = Test::Nginx->new()->has(qw/http fastcgi cache/)->plan(5)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 master_process off;
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 fastcgi_cache_path %%TESTDIR%%/cache levels=1:2
42 keys_zone=NAME:10m;
43
44 server {
45 listen 127.0.0.1:8080;
46 server_name localhost;
47
48 location / {
49 fastcgi_pass 127.0.0.1:8081;
50 fastcgi_param REQUEST_URI $request_uri;
51 fastcgi_cache NAME;
52 fastcgi_cache_key $request_uri;
53 fastcgi_cache_valid 302 1m;
54 }
55 }
56 }
57
58 EOF
59
60 $t->run_daemon(\&fastcgi_daemon);
61 $t->run();
62
63 ###############################################################################
64
65 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
66 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request cached');
67
68 unlike(http_head('/'), qr/SEE-THIS/, 'no data in cached HEAD');
69
70 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled');
71 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr cached');
72
73 ###############################################################################
74
75 sub fastcgi_daemon {
76 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
77 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
78 $socket);
79
80 my $count;
81 while( $request->Accept() >= 0 ) {
82 $count++;
83
84 if ($ENV{REQUEST_URI} eq '/stderr') {
85 warn "sample stderr text" x 512;
86 }
87
88 print <<EOF;
89 Location: http://127.0.0.1:8080/redirect
90 Content-Type: text/html
91
92 SEE-THIS
93 $count
94 EOF
95 }
96
97 FCGI::CloseSocket($socket);
98 }
99
100 ###############################################################################