comparison image_filter_finalize.t @ 525:13eafeb7d9cb

Tests: some filter_finalize tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 24 Feb 2015 18:11:42 +0300
parents
children 625cbbfd66b3
comparison
equal deleted inserted replaced
524:084f8c8cb648 525:13eafeb7d9cb
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for http filter finalize code.
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 plan(skip_all => 'win32') if $^O eq 'MSWin32';
25
26 my $t = Test::Nginx->new()
27 ->has(qw/http proxy cache image_filter limit_req rewrite/)->plan(4)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 proxy_cache_path %%TESTDIR%%/cache keys_zone=cache:1m;
41
42 limit_req_zone $binary_remote_addr zone=limit:1m rate=50r/m;
43
44 log_format time "$request_uri:$status:$upstream_response_time";
45 access_log time.log time;
46
47 upstream u {
48 server 127.0.0.1:8081;
49 server 127.0.0.1:8081;
50 server 127.0.0.1:8081;
51 server 127.0.0.1:8081;
52 server 127.0.0.1:8080;
53 }
54
55 server {
56 listen 127.0.0.1:8080;
57 server_name localhost;
58
59 # this used to cause a segmentation fault before 07f028df3879 (1.3.1)
60 # http://nginx.org/pipermail/nginx/2011-January/024703.html
61
62 location /t1 {
63 proxy_pass http://127.0.0.1:8080/bad;
64 proxy_cache cache;
65 proxy_cache_valid any 1h;
66
67 image_filter resize 150 100;
68 error_page 415 = /empty;
69 }
70
71 location /empty {
72 return 204;
73 }
74
75 location /bad {
76 return 404;
77 }
78
79 # another segfault, introduced in 204b780a89de (1.3.0),
80 # fixed in 07f028df3879 (1.3.1)
81
82 location /t2 {
83 proxy_pass http://127.0.0.1:8080/big;
84 proxy_store on;
85
86 image_filter_buffer 10m;
87 image_filter resize 150 100;
88 error_page 415 = /empty;
89 }
90
91 location /big {
92 # big enough static file
93 }
94
95 # filter finalization may cause duplicate upstream finalization,
96 # resulting in wrong $upstream_response time,
97 # http://nginx.org/pipermail/nginx-devel/2015-February/006539.html
98
99 # note that we'll need upstream response time to be at least 1 second,
100 # and at least 4 failed requests to make sure r->upstream_states will
101 # not be reallocated
102
103 location /t3 {
104 proxy_pass http://u/slow;
105 proxy_buffering off;
106
107 image_filter resize 150 100;
108 error_page 415 = /upstream;
109 }
110
111 location /slow {
112 limit_req zone=limit burst=5;
113 }
114
115 location /upstream {
116 proxy_pass http://127.0.0.1:8080/empty;
117 }
118
119 location /time.log {
120 # access to log
121 }
122 }
123
124 server {
125 listen 127.0.0.1:8081;
126 server_name localhost;
127 return 444;
128 }
129 }
130
131 EOF
132
133 $t->write_file('big', "x" x 10240000);
134 $t->write_file('slow', "x");
135
136 $t->run();
137
138 ###############################################################################
139
140 like(http_get('/t1'), qr/HTTP/, 'image filter and cache');
141 like(http_get('/t2'), qr/HTTP/, 'image filter and store');
142
143 TODO: {
144 local $TODO = 'not yet';
145
146 http_get('/slow');
147 http_get('/t3');
148 like(http_get('/time.log'), qr!/t3:.*, 1\.!, 'upstream response time');
149
150 }
151
152 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
153
154 ###############################################################################