Mercurial > hg > nginx-tests
annotate limit_req_delay.t @ 1434:fc8341cf92a3
Tests: removed ngx_parse_inet6_url() "::" test from proxy.t.
It results in WSAEADDRNOTAVAIL on win32, be the connection errors detected,
which leads to connect() alert. On other systems, connect() is successful
but it uses the default port (80), which is out of documented ports range.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 24 Jan 2019 17:05:04 +0300 |
parents | d22717fcabdb |
children | 144c6ce732e4 |
rev | line source |
---|---|
1404
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx limit_req module, delay parameter. |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_end /; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http limit_req/); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
1416
d22717fcabdb
Tests: adjusted rate in limit_req_delay.t for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1404
diff
changeset
|
39 limit_req_zone $binary_remote_addr zone=one:1m rate=30r/m; |
1404
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 limit_req zone=one delay=1 burst=2; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 add_header X-Time $request_time; |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 EOF |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 $t->write_file('delay.html', 'XtestX'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 $t->try_run('no limit_req delay')->plan(4); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 ############################################################################### |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 like(http_get('/delay.html'), qr/^HTTP\/1.. 200 /m, 'request'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 like(http_get('/delay.html'), qr/X-Time: 0.000/, 'not yet delayed'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 my $s = http_get('/delay.html', start => 1, sleep => 0.2); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 like(http_get('/delay.html'), qr/^HTTP\/1.. 503 /m, 'rejected'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 like(http_end($s), qr/^HTTP\/1.. 200 .*X-Time: (?!0.000)/ms, 'delayed'); |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
d316f1aff10a
Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 ############################################################################### |