Mercurial > hg > nginx-tests
annotate limit_req_delay.t @ 1940:aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Used to get rid of "quic UDP datagram is too small for initial packet" messages.
In future, we may need this to reconsider to allow mocking with custom padding,
but for now suppressing such messages is sufficiently good enough.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 11 Dec 2023 14:01:49 +0400 |
parents | 144c6ce732e4 |
children |
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 |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1416
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(4); |
1404
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'); |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1416
diff
changeset
|
55 $t->run(); |
1404
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 ############################################################################### |