Mercurial > hg > nginx-tests
annotate fastcgi_cache.t @ 165:fca70f483608
Tests: fix previous commit (print original message length).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 01 Aug 2011 21:50:01 +0400 |
parents | b714d6df958c |
children | c0ae29632905 |
rev | line source |
---|---|
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend with cache. |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require FCGI; }; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http fastcgi cache/)->plan(5) |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 master_process off; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 daemon off; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 fastcgi_cache_path %%TESTDIR%%/cache levels=1:2 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 keys_zone=NAME:10m; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 listen 127.0.0.1:8080; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 server_name localhost; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 location / { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 fastcgi_pass 127.0.0.1:8081; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 fastcgi_param REQUEST_URI $request_uri; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 fastcgi_cache NAME; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 fastcgi_cache_key $request_uri; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 fastcgi_cache_valid 302 1m; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 EOF |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 $t->run_daemon(\&fastcgi_daemon); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $t->run(); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request cached'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 unlike(http_head('/'), qr/SEE-THIS/, 'no data in cached HEAD'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr cached'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 sub fastcgi_daemon { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 $socket); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 my $count; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 while( $request->Accept() >= 0 ) { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 $count++; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 if ($ENV{REQUEST_URI} eq '/stderr') { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 warn "sample stderr text" x 512; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 print <<EOF; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 Location: http://127.0.0.1:8080/redirect |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 Content-Type: text/html |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 SEE-THIS |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 $count |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 EOF |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 FCGI::CloseSocket($socket); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 ############################################################################### |