Mercurial > hg > nginx-tests
annotate stream_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 | f3ba4c74de31 |
rev | line source |
---|---|
1532
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for limit_conn_dry_run directive, limit_conn_status variable. |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_limit_conn http/); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 stream { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 limit_conn_zone $binary_remote_addr zone=zone:1m; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 log_format test $server_port:$limit_conn_status; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 access_log %%TESTDIR%%/test.log test; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:8080; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 proxy_timeout 5s; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8081; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 listen 127.0.0.1:8082; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 limit_conn_dry_run on; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 listen 127.0.0.1:8083; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 http { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 %%TEST_GLOBALS_HTTP%% |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 listen 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 server_name localhost; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 location / { } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 EOF |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $t->write_file('index.html', 'OK'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t->try_run('no limit_conn_dry_run/limit_conn_status')->plan(9); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 my ($p, $p1, $p2, $p3) = (port(8080), port(8081), port(8082), port(8083)); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 is(stream("127.0.0.1:$p")->io("GET /\n"), 'OK', 'passed'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 my $s = stream('127.0.0.1:' . port(8080)); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $s->write("GET"); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 is(stream("127.0.0.1:$p1")->io("GET /\n"), '', 'rejected'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 is(stream("127.0.0.1:$p2")->io("GET /\n"), 'OK', 'rejected dry run'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 is(stream("127.0.0.1:$p3")->io("GET /\n"), 'OK', 'no limit'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 undef $s; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 $t->stop(); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 like($t->read_file('error.log'), qr/limiting connections, dry/, 'log dry run'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 like($t->read_file('test.log'), qr|$p:PASSED|, 'log passed'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 like($t->read_file('test.log'), qr|$p1:REJECTED$|m, 'log rejected'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 like($t->read_file('test.log'), qr|$p2:REJECTED_DRY_RUN|, 'log rejected dry'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 like($t->read_file('test.log'), qr|$p3:-|, 'log not found'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |