Mercurial > hg > nginx-tests
annotate proxy_limit_rate.t @ 627:cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sometimes, on slow hosts, it may get quite some time to complete request
delayed with proxy_limit_rate, and we still need to known how much it took.
The timeout value used internally in the http() library routine is not enough.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 09 Jul 2015 13:46:43 +0300 |
parents | 907e89fba9c3 |
children | 0940773278c7 |
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 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
536
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2); |
482
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; |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
46 add_header X-Msec $msec; |
482
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 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 location /data { |
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 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 EOF |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 $t->write_file('data', 'X' x 40000); |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
536
diff
changeset
|
57 $t->run(); |
482
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 |
627
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
61 my $s = http_get('/', start => 1); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
62 my $r = http_end_gentle($s); |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
64 my ($t1) = $r =~ /X-Msec: (\d+)/; |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 my $diff = time() - $t1; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 # 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
|
68 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 cmp_ok(abs($diff - 3), '<=', 1, 'proxy_limit_rate'); |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 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
|
71 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ############################################################################### |
627
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
73 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
74 sub http_end_gentle { |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
75 my ($s) = @_; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
76 my $reply; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
77 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
78 eval { |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
79 local $SIG{ALRM} = sub { die "timeout\n" }; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
80 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
81 alarm(8); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
82 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
83 local $/; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
84 $reply = $s->getline(); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
85 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
86 alarm(0); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
87 }; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
88 alarm(0); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
89 if ($@) { |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
90 log_in("died: $@"); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
91 return undef; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
92 } |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
93 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
94 log_in($reply); |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
95 return $reply; |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
96 } |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
97 |
cb35a9ec4428
Tests: adjusted proxy_limit_rate test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
98 ############################################################################### |