Mercurial > hg > nginx-tests
comparison limit_conn_dry_run.t @ 1532:9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 19 Nov 2019 21:03:41 +0300 |
parents | |
children | 5ac6efbe5552 |
comparison
equal
deleted
inserted
replaced
1531:65eb942993ad | 1532:9d5996c3f5b8 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for limit_conn_dry_run directive, limit_conn_status variable. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 limit_req_zone $binary_remote_addr zone=req:1m rate=30r/m; | |
40 limit_conn_zone $binary_remote_addr zone=zone:1m; | |
41 | |
42 log_format test $uri:$limit_conn_status; | |
43 | |
44 server { | |
45 listen 127.0.0.1:8081; | |
46 server_name localhost; | |
47 | |
48 location /w { | |
49 limit_req zone=req burst=10; | |
50 } | |
51 } | |
52 | |
53 server { | |
54 listen 127.0.0.1:8080; | |
55 server_name localhost; | |
56 | |
57 add_header X-Status $limit_conn_status always; | |
58 access_log %%TESTDIR%%/test.log test; | |
59 | |
60 location /reject { | |
61 proxy_pass http://127.0.0.1:8081/w; | |
62 limit_conn zone 1; | |
63 } | |
64 | |
65 location /dry { | |
66 limit_conn zone 1; | |
67 limit_conn_dry_run on; | |
68 } | |
69 | |
70 location / { } | |
71 } | |
72 } | |
73 | |
74 EOF | |
75 | |
76 $t->write_file('w', ''); | |
77 $t->try_run('no limit_conn_dry_run/limit_conn_status')->plan(6); | |
78 | |
79 ############################################################################### | |
80 | |
81 like(http_get('/reject'), qr/ 200 .*PASSED/s, 'passed'); | |
82 | |
83 my $s = http_get('/reject', start => 1); | |
84 like(http_get('/reject'), qr/ 503 .*REJECTED(?!_)/s, 'rejected'); | |
85 like(http_get('/dry'), qr/ 404 .*REJECTED_DRY_RUN/s, 'rejected dry run'); | |
86 unlike(http_get('/'), qr/X-Status/, 'no limit'); | |
87 | |
88 close $s; | |
89 | |
90 $t->stop(); | |
91 | |
92 like($t->read_file('error.log'), qr/limiting connections, dry/, 'log dry run'); | |
93 like($t->read_file('test.log'), qr|^/:-|m, 'log not found'); | |
94 | |
95 ############################################################################### |