Mercurial > hg > nginx-tests
annotate proxy_limit_rate.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | 516070bada7d |
children | b113eeca94ad |
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 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
482
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 / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 proxy_pass http://127.0.0.1:8080/data; |
981
516070bada7d
Tests: unbreak proxy_limit_rate.t on hosts with larger page sizes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
45 proxy_buffer_size 4k; |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 proxy_limit_rate 12000; |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
47 add_header X-Msec $msec; |
482
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 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 location /data { |
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 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 EOF |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 $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
|
58 $t->run(); |
482
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 ############################################################################### |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
628
0940773278c7
Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
627
diff
changeset
|
62 my $r = http_get('/'); |
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 |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
628
diff
changeset
|
67 # four chunks are split with three 1s delays |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
628
diff
changeset
|
69 cmp_ok($diff, '>=', 3, 'proxy_limit_rate'); |
482
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 ############################################################################### |