-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathimage_filter_finalize.t
152 lines (107 loc) · 3.66 KB
/
image_filter_finalize.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/perl
# (C) Maxim Dounin
# Tests for http filter finalize code.
###############################################################################
use warnings;
use strict;
use Test::More;
BEGIN { use FindBin; chdir($FindBin::Bin); }
use lib 'lib';
use Test::Nginx;
###############################################################################
select STDERR; $| = 1;
select STDOUT; $| = 1;
my $t = Test::Nginx->new()->has(qw/http proxy cache image_filter limit_req/)
->has(qw/rewrite/)->plan(3)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
daemon off;
events {
}
http {
%%TEST_GLOBALS_HTTP%%
proxy_cache_path %%TESTDIR%%/cache keys_zone=cache:1m;
limit_req_zone $binary_remote_addr zone=limit:1m rate=25r/m;
log_format time "$request_uri:$status:$upstream_response_time";
access_log time.log time;
upstream u {
server 127.0.0.1:8081;
server 127.0.0.1:8081;
server 127.0.0.1:8081;
server 127.0.0.1:8081;
server 127.0.0.1:8080;
}
server {
listen 127.0.0.1:8080;
server_name localhost;
# this used to cause a segmentation fault before d2143f11c (1.3.1)
# http://nginx.org/pipermail/nginx/2011-January/024703.html
location /t1 {
proxy_pass http://127.0.0.1:8080/bad;
proxy_cache cache;
proxy_cache_valid any 1h;
image_filter resize 150 100;
error_page 415 = /empty;
}
location /empty {
return 204;
}
location /bad {
return 404;
}
# another segfault, introduced in e302ed6fc (1.3.0),
# fixed in d2143f11c (1.3.1)
location /t2 {
proxy_pass http://127.0.0.1:8080/big;
proxy_store on;
image_filter_buffer 10m;
image_filter resize 150 100;
error_page 415 = /empty;
}
location /big {
# big enough static file
}
# filter finalization may cause duplicate upstream finalization,
# resulting in wrong $upstream_response_time,
# http://nginx.org/pipermail/nginx-devel/2015-February/006539.html
# note that we'll need upstream response time to be at least 1 second,
# and at least 4 failed requests to make sure r->upstream_states will
# not be reallocated
location /t3 {
proxy_pass http://u/slow;
proxy_buffering off;
image_filter resize 150 100;
error_page 415 = /upstream;
}
location /slow {
limit_req zone=limit burst=5;
}
location /upstream {
proxy_pass http://127.0.0.1:8080/empty;
}
location /time.log {
# access to log
}
}
server {
listen 127.0.0.1:8081;
server_name localhost;
return 444;
}
}
EOF
$t->write_file('big', "x" x 10240000);
$t->write_file('slow', "x");
$t->run();
###############################################################################
like(http_get('/t1'), qr/HTTP/, 'image filter and cache');
like(http_get('/t2'), qr/HTTP/, 'image filter and store');
http_get('/slow');
http_get('/t3');
like(http_get('/time.log'), qr!/t3:.*, [1-9]\.!, 'upstream response time');
# "aio_write" is used to produce the following alert on some platforms:
# "readv() failed (9: Bad file descriptor) while reading upstream"
$t->todo_alerts() if $t->read_file('nginx.conf') =~ /aio_write on/
and $t->read_file('nginx.conf') =~ /aio threads/
and !$t->has_version('1.25.4');
###############################################################################