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