annotate limit-req.t @ 113:5d31f920eda9

Tests: whitespace cleanup, no functional changes.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 24 Nov 2009 13:57:43 +0300
parents 1c0ec30614c6
children 8ac1faaddd2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for nginx limit_req module.
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
24 my $t = Test::Nginx->new()->plan(5);
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 $t->write_file_expand('nginx.conf', <<'EOF');
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 103
diff changeset
28 %%TEST_GLOBALS%%
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 103
diff changeset
29
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30 master_process off;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 daemon off;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 events {
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 }
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 http {
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 103
diff changeset
37 %%TEST_GLOBALS_HTTP%%
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
39 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
40 limit_req_zone $binary_remote_addr zone=long:10m rate=1r/m;
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
41 limit_req_zone $binary_remote_addr zone=fast:10m rate=1000r/s;
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 server {
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 listen 127.0.0.1:8080;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 server_name localhost;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 location / {
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 limit_req zone=one burst=1 nodelay;
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 }
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
49 location /long {
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
50 limit_req zone=long burst=5;
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
51 }
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
52 location /fast {
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
53 limit_req zone=fast burst=1;
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
54 }
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 }
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 }
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 EOF
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 $t->write_file('test1.html', 'XtestX');
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
61 $t->write_file('long.html', "1234567890\n" x (1 << 16));
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
62 $t->write_file('fast.html', 'XtestX');
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 $t->run();
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 ###############################################################################
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'request');
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 http_get('/test1.html');
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 like(http_get('/test1.html'), qr/^HTTP\/1.. 503 /m, 'request rejected');
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
70 http_get('/test1.html');
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
71 http_get('/test1.html');
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
73 # Second request will be delayed by limit_req, make sure it isn't truncated.
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
74 # The bug only manifests itself if buffer will be filled, so sleep for a while
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
75 # before reading response.
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
76
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
77 my $l1 = length(http_get('/long.html'));
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
78 my $l2 = length(http_get('/long.html', sleep => 1.1));
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
79 is($l2, $l1, 'delayed big request not truncated');
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 78
diff changeset
80
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
81 # make sure rejected requests are not counted, and access is again allowed
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
82 # after 1/rate seconds
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
83
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
84 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'rejects not counted');
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
85
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
86 # make sure negative excess values are handled properly
113
5d31f920eda9 Tests: whitespace cleanup, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
87
103
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
88 http_get('/fast.html');
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
89 select undef, undef, undef, 0.1;
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
90 like(http_get('/fast.html'), qr/^HTTP\/1.. 200 /m, 'negative excess');
4ae2198b97ec Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 97
diff changeset
91
78
c893908c1a44 Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 ###############################################################################