Mercurial > hg > nginx-tests
annotate proxy_limit_rate.t @ 1962:f1ba89f735ba
Tests: fixed auth_basic.t on OpenBSD.
OpenBSD does not provide any crypt() schemes except bcrypt-based "$2"
anymore. As such, relevant tests are now skipped not for win32 only,
but based on crypt() results.
Note that just testing crypt('password', 'salt') is not enough, since
Perl on win32 provides its own crypt() implementation, which is able
to handle traditional DES crypt(), but rejects "$1$".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 05 May 2024 23:56:07 +0300 |
parents | 06fbbf1706bd |
children |
rev | line source |
---|---|
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for the proxy_limit_rate directive. |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1255
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/)->plan(4); |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
1255
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
39 upstream u { |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
40 server 127.0.0.1:8080; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
41 keepalive 1; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
42 } |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
43 |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 proxy_pass http://127.0.0.1:8080/data; |
981
516070bada7d
Tests: unbreak proxy_limit_rate.t on hosts with larger page sizes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
50 proxy_buffer_size 4k; |
1503
06fbbf1706bd
Tests: tune proxy_limit_rate tests for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
51 proxy_limit_rate 20000; |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
52 add_header X-Msec $msec; |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
1255
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
55 location /keepalive { |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
56 proxy_http_version 1.1; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
57 proxy_set_header Connection ""; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
58 proxy_pass http://u/data; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
59 proxy_buffer_size 4k; |
1503
06fbbf1706bd
Tests: tune proxy_limit_rate tests for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
60 proxy_limit_rate 20000; |
1255
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
61 add_header X-Msec $msec; |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
62 } |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
63 |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 location /data { |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 EOF |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->write_file('data', 'X' x 40000); |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
536
diff
changeset
|
72 $t->run(); |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 ############################################################################### |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
628
0940773278c7
Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
627
diff
changeset
|
76 my $r = http_get('/'); |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
536
c2481c6b748f
Tests: adjusted proxy_limit_rate test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
482
diff
changeset
|
78 my ($t1) = $r =~ /X-Msec: (\d+)/; |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 my $diff = time() - $t1; |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
628
diff
changeset
|
81 # four chunks are split with three 1s delays |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1503
06fbbf1706bd
Tests: tune proxy_limit_rate tests for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
83 cmp_ok($diff, '>=', 1, 'proxy_limit_rate'); |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 like($r, qr/^(XXXXXXXXXX){4000}\x0d?\x0a?$/m, 'response body'); |
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
1255
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
86 # in case keepalive connection was saved with the delayed flag, |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
87 # the read timer used to be a delay timer in the next request |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
88 |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
89 like(http_get('/keepalive'), qr/200 OK/, 'keepalive'); |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
90 like(http_get('/keepalive'), qr/200 OK/, 'keepalive 2'); |
b113eeca94ad
Tests: added proxy_limit_rate tests with upstream keepalive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
981
diff
changeset
|
91 |
482
6d35acdf9a61
Tests: proxy_limit_rate simple test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 ############################################################################### |