Skip to content

Commit bc6ba72

Browse files
committed
Tests: adjusted proxy_limit_rate tests.
Notably, the end time is now also taken from nginx for accuracy.
1 parent 5b95d93 commit bc6ba72

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

proxy_limit_rate.t

+23-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use Test::More;
1515
BEGIN { use FindBin; chdir($FindBin::Bin); }
1616

1717
use lib 'lib';
18-
use Test::Nginx;
18+
use Test::Nginx qw/ :DEFAULT http_content /;
1919

2020
###############################################################################
2121

@@ -45,20 +45,19 @@ http {
4545
listen 127.0.0.1:8080;
4646
server_name localhost;
4747
48+
proxy_limit_rate 20000;
49+
proxy_buffer_size 4k;
50+
4851
location / {
4952
proxy_pass http://127.0.0.1:8080/data;
50-
proxy_buffer_size 4k;
51-
proxy_limit_rate 20000;
52-
add_header X-Msec $msec;
53+
add_header X-Msec $msec;
54+
add_trailer X-Msec $msec;
5355
}
5456
5557
location /keepalive {
5658
proxy_http_version 1.1;
5759
proxy_set_header Connection "";
5860
proxy_pass http://u/data;
59-
proxy_buffer_size 4k;
60-
proxy_limit_rate 20000;
61-
add_header X-Msec $msec;
6261
}
6362
6463
location /data {
@@ -73,15 +72,10 @@ $t->run();
7372

7473
###############################################################################
7574

76-
my $r = http_get('/');
77-
78-
my ($t1) = $r =~ /X-Msec: (\d+)/;
79-
my $diff = time() - $t1;
80-
81-
# four chunks are split with three 1s delays
75+
my ($body, $t1, $t2) = get('/');
8276

83-
cmp_ok($diff, '>=', 1, 'proxy_limit_rate');
84-
like($r, qr/^(XXXXXXXXXX){4000}\x0d?\x0a?$/m, 'response body');
77+
cmp_ok($t2 - $t1, '>=', 1, 'proxy_limit_rate');
78+
is($body, 'X' x 40000, 'response body');
8579

8680
# in case keepalive connection was saved with the delayed flag,
8781
# the read timer used to be a delay timer in the next request
@@ -90,3 +84,17 @@ like(http_get('/keepalive'), qr/200 OK/, 'keepalive');
9084
like(http_get('/keepalive'), qr/200 OK/, 'keepalive 2');
9185

9286
###############################################################################
87+
88+
sub get {
89+
my ($uri) = @_;
90+
my $r = http(<<EOF);
91+
GET $uri HTTP/1.1
92+
Host: localhost
93+
Connection: close
94+
95+
EOF
96+
97+
http_content($r), $r =~ /X-Msec: (\d+)/g;
98+
}
99+
100+
###############################################################################

0 commit comments

Comments
 (0)