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