comparison limit_req_delay.t @ 1404:d316f1aff10a

Tests: "limit_req .. delay" tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 23 Nov 2018 19:07:29 +0300
parents
children d22717fcabdb
comparison
equal deleted inserted replaced
1403:3783b937a1dc 1404:d316f1aff10a
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for nginx limit_req module, delay parameter.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx qw/ :DEFAULT http_end /;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http limit_req/);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/s;
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 location / {
46 limit_req zone=one delay=1 burst=2;
47 add_header X-Time $request_time;
48 }
49 }
50 }
51
52 EOF
53
54 $t->write_file('delay.html', 'XtestX');
55 $t->try_run('no limit_req delay')->plan(4);
56
57 ###############################################################################
58
59 like(http_get('/delay.html'), qr/^HTTP\/1.. 200 /m, 'request');
60 like(http_get('/delay.html'), qr/X-Time: 0.000/, 'not yet delayed');
61 my $s = http_get('/delay.html', start => 1, sleep => 0.2);
62 like(http_get('/delay.html'), qr/^HTTP\/1.. 503 /m, 'rejected');
63 like(http_end($s), qr/^HTTP\/1.. 200 .*X-Time: (?!0.000)/ms, 'delayed');
64
65 ###############################################################################