Mercurial > hg > nginx-tests
annotate limit_req_dry_run.t @ 1982:fb25cbe9d4ec
Tests: explicit Valgrind support.
Valgrind logging is done to a separate file, as it is not able to
follow stderr redirection within nginx or append to a file without
corrupting it. Further, Valgrind logging seems to interfere with
error suppression in tests, and catches various startup errors and
warnings, so the log is additionally filtered.
Since startup under Valgrind can be really slow, timeout in waitforfile()
was changed to 10 seconds.
Prodded by Robert Mueller.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 31 May 2024 06:23:00 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx limit_req module, limit_req_dry_run directive. |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http limit_req/); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
41 log_format test $uri:$limit_req_status; |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
42 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:8080; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 limit_req_dry_run on; |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
48 add_header X-Status $limit_req_status always; |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
49 access_log %%TESTDIR%%/test.log test; |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 location /delay { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 limit_req zone=one burst=2; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 location /reject { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 limit_req zone=one; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /reject/off { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 limit_req zone=one; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 limit_req_dry_run off; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
64 |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
65 location / { } |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 EOF |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->write_file('delay', 'SEE-THIS'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $t->write_file('reject', 'SEE-THIS'); |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1531
diff
changeset
|
73 $t->run()->plan(8); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
77 like(http_get('/delay'), qr/ 200 .*PASSED/ms, 'dry run - passed'); |
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
78 like(http_get('/delay'), qr/ 200 .*DELAYED_DRY_RUN/ms, 'dry run - delayed'); |
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
79 like(http_get('/reject'), qr/ 200 .*REJECTED_DRY_RUN/ms, 'dry run - rejected'); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
81 like(http_get('/reject/off'), qr/ 503 .*REJECTED/ms, 'dry run off - rejected'); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
83 unlike(http_get('/'), qr/X-Status/, 'no limit'); |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
84 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t->stop(); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like($t->read_file('error.log'), qr/delaying request, dry/, 'log - delay'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like($t->read_file('error.log'), qr/limiting requests, dry/, 'log - reject'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
90 like($t->read_file('test.log'), qr|^/:-|m, 'log - not found'); |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
91 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 ############################################################################### |