Mercurial > hg > nginx-tests
annotate limit_conn_complex.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 | 2cd00179f4b2 |
rev | line source |
---|---|
475
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # limit_req based tests for limit_conn module with complex keys. |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
477
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/)->plan(4); |
475
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 $t->write_file_expand('nginx.conf', <<'EOF'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 daemon off; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 events { |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 http { |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 limit_req_zone $binary_remote_addr$arg_r zone=req:1m rate=1r/s; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 limit_conn_zone $binary_remote_addr$arg_c zone=conn:1m; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 listen 127.0.0.1:8080; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 server_name localhost; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 location / { |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 limit_conn conn 1; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 location /w { |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 limit_conn conn 1; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 proxy_pass http://127.0.0.1:8080/req; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /req { |
477
c94fc8e41f5f
Tests: adjusted limit_conn_complex.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
475
diff
changeset
|
60 limit_req zone=req burst=2; |
475
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 EOF |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
477
diff
changeset
|
67 $t->run(); |
475
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $s; |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 # charge limit_req |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 http_get('/req'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 # limit_req tests |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $s = http_get('/req', start => 1); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 ok(!IO::Select->new($s)->can_read(0.1), 'limit_req same key'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $s = http_get('/req?r=2', start => 1); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ok(IO::Select->new($s)->can_read(0.1), 'limit_req different key'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 # limit_conn tests |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $s = http_get('/w', start => 1); |
477
c94fc8e41f5f
Tests: adjusted limit_conn_complex.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
475
diff
changeset
|
88 select undef, undef, undef, 0.2; |
475
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 like(http_get('/'), qr/^HTTP\/1.. 503 /, 'limit_conn same key'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 unlike(http_get('/?c=2'), qr/^HTTP\/1.. 503 /, 'limit_conn different key'); |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
c872b2c9645f
Tests: tests for limit_conn and limit_req with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 ############################################################################### |