Mercurial > hg > nginx-tests
annotate proxy_limit_rate.t @ 572:ca54b445d982
Tests: masked nginx bug in proxy next upstream.
When iterating through several next upstreams per a worker cycle,
a previously reported event about upstream connection error may
be improperly applied to the next upstream, thus leading to the
invalid connection error. E.g., in kqueue, where the problem is
visible, this is caused by "ev->instance" that does not tolerate
more than one next upstream at once, and kevents placed on the
kqueue separately for read and write events.
The change is to limit test case to the only one next upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 May 2015 11:54:24 +0300 |
parents | 907e89fba9c3 |
children | cb35a9ec4428 |
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 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 my $r = http_get('/'); |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
63 my ($t1) = $r =~ /X-Msec: (\d+)/; |
482
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 ############################################################################### |