annotate limit_conn.t @ 1248:70192b1baf01

Tests: added exception test to stream_js.t using 'require'. The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't currently provide an easy way to check its version, whilst we are obligated to gracefully handle such cases somehow. With such an addition of 'require', now the tests are skipped instead on the previous versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Nov 2017 13:16:39 +0300
parents 196d33c2bb45
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # limit_req based tests for nginx limit_conn module.
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 use lib 'lib';
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 ###############################################################################
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
1020
196d33c2bb45 Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 974
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/);
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
820
45471a9017cc Tests: TODO 'phantom event' alerts in limit_conn.t on Solaris.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
26 $t->write_file_expand('nginx.conf', <<'EOF')->plan(8);
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
386
1b205a3332de Tests: adjusted limit_req rate value.
Sergey Kandaurov <pluknet@nginx.com>
parents: 318
diff changeset
38 limit_req_zone $binary_remote_addr zone=req:1m rate=30r/m;
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 limit_conn_zone $binary_remote_addr zone=zone:1m;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 limit_conn_zone $binary_remote_addr zone=zone2:1m;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 limit_conn_zone $binary_remote_addr zone=custom:1m;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
45 listen 127.0.0.1:8081;
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server_name localhost;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 location /w {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 limit_req zone=req burst=10;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
54 listen 127.0.0.1:8080;
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 server_name localhost;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
58 proxy_pass http://127.0.0.1:8081;
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 limit_conn zone 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 location /1 {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 limit_conn zone 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 location /zone {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 limit_conn zone2 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location /unlim {
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 limit_conn zone 5;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 location /custom {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
75 proxy_pass http://127.0.0.1:8081/;
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 limit_conn_log_level info;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 limit_conn_status 501;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 limit_conn custom 1;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 }
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 EOF
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $t->run();
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 ###############################################################################
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 # charge limit_req
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 http_get('/w');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 # same and other zones in different locations
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 386
diff changeset
95 my $s = http_get('/w', start => 1);
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 like(http_get('/'), qr/^HTTP\/1.. 503 /, 'rejected');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 like(http_get('/1'), qr/^HTTP\/1.. 503 /, 'rejected different location');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 unlike(http_get('/zone'), qr/^HTTP\/1.. 503 /, 'passed different zone');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 close $s;
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 unlike(http_get('/1'), qr/^HTTP\/1.. 503 /, 'passed');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 # custom error code and log level
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 386
diff changeset
105 $s = http_get('/custom/w', start => 1);
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 like(http_get('/custom'), qr/^HTTP\/1.. 501 /, 'limit_conn_status');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
469
1c5a8265f386 Tests: fixed matching for limit_conn_log_level.
Valentin Bartenev <vbart@nginx.com>
parents: 468
diff changeset
108 like($t->read_file('error.log'),
1c5a8265f386 Tests: fixed matching for limit_conn_log_level.
Valentin Bartenev <vbart@nginx.com>
parents: 468
diff changeset
109 qr/\[info\].*limiting connections by zone "custom"/,
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 'limit_conn_log_level');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 # limited after unlimited
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 386
diff changeset
114 $s = http_get('/w', start => 1);
313
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 like(http_get('/unlim'), qr/404 Not Found/, 'unlimited passed');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 like(http_get('/'), qr/503 Service/, 'limited rejected');
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117
9daf28f20766 Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 ###############################################################################