Mercurial > hg > nginx-tests
annotate limit_req_delay.t @ 1905:f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
The parse_stream() routine has had a missing explicit return if there were no
streams received. In Perl < 5.24 this used to return no value, or an empty
array in the list context. In modern Perl this returns an empty value, or an
array of 1 element, which made the check for last index of the returned array
work rather by accident.
The fix is to return explicitly and to check the array size in callers instead.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 06 Jun 2023 18:50:07 +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 ############################################################################### |