comparison proxy_limit_rate.t @ 482:6d35acdf9a61

Tests: proxy_limit_rate simple test.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 28 Oct 2014 14:10:50 +0300
parents
children c2481c6b748f
comparison
equal deleted inserted replaced
481:7e823c8f7d31 482:6d35acdf9a61
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for the proxy_limit_rate directive.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http proxy/);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 location / {
44 proxy_pass http://127.0.0.1:8080/data;
45 proxy_limit_rate 12000;
46 }
47
48 location /data {
49 }
50 }
51 }
52
53 EOF
54
55 $t->write_file('data', 'X' x 40000);
56 $t->try_run('no proxy_limit_rate')->plan(2);
57
58 ###############################################################################
59
60 my $t1 = time();
61
62 my $r = http_get('/');
63
64 my $diff = time() - $t1;
65
66 # four chunks are split with three 1s delays + 1s error
67
68 cmp_ok(abs($diff - 3), '<=', 1, 'proxy_limit_rate');
69 like($r, qr/^(XXXXXXXXXX){4000}\x0d?\x0a?$/m, 'response body');
70
71 ###############################################################################