comparison stream_limit_conn_dry_run.t @ 1532:9d5996c3f5b8

Tests: limit_conn_dry_run, $limit_conn_status tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 19 Nov 2019 21:03:41 +0300
parents
children f3ba4c74de31
comparison
equal deleted inserted replaced
1531:65eb942993ad 1532:9d5996c3f5b8
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for limit_conn_dry_run directive, limit_conn_status variable.
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;
19 use Test::Nginx::Stream qw/ stream /;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/stream stream_limit_conn http/);
27
28 $t->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 stream {
38 limit_conn_zone $binary_remote_addr zone=zone:1m;
39
40 log_format test $server_port:$limit_conn_status;
41 access_log %%TESTDIR%%/test.log test;
42
43 server {
44 listen 127.0.0.1:8080;
45 proxy_pass 127.0.0.1:8084;
46 limit_conn zone 1;
47
48 proxy_timeout 5s;
49 }
50
51 server {
52 listen 127.0.0.1:8081;
53 proxy_pass 127.0.0.1:8084;
54 limit_conn zone 1;
55 }
56
57 server {
58 listen 127.0.0.1:8082;
59 proxy_pass 127.0.0.1:8084;
60 limit_conn zone 1;
61
62 limit_conn_dry_run on;
63 }
64
65 server {
66 listen 127.0.0.1:8083;
67 proxy_pass 127.0.0.1:8084;
68 }
69 }
70
71 http {
72 %%TEST_GLOBALS_HTTP%%
73
74 server {
75 listen 127.0.0.1:8084;
76 server_name localhost;
77
78 location / { }
79 }
80 }
81
82 EOF
83
84 $t->write_file('index.html', 'OK');
85 $t->try_run('no limit_conn_dry_run/limit_conn_status')->plan(9);
86
87 ###############################################################################
88
89 my ($p, $p1, $p2, $p3) = (port(8080), port(8081), port(8082), port(8083));
90
91 is(stream("127.0.0.1:$p")->io("GET /\n"), 'OK', 'passed');
92
93 my $s = stream('127.0.0.1:' . port(8080));
94 $s->write("GET");
95
96 is(stream("127.0.0.1:$p1")->io("GET /\n"), '', 'rejected');
97 is(stream("127.0.0.1:$p2")->io("GET /\n"), 'OK', 'rejected dry run');
98 is(stream("127.0.0.1:$p3")->io("GET /\n"), 'OK', 'no limit');
99
100 undef $s;
101
102 $t->stop();
103
104 like($t->read_file('error.log'), qr/limiting connections, dry/, 'log dry run');
105 like($t->read_file('test.log'), qr|$p:PASSED|, 'log passed');
106 like($t->read_file('test.log'), qr|$p1:REJECTED$|m, 'log rejected');
107 like($t->read_file('test.log'), qr|$p2:REJECTED_DRY_RUN|, 'log rejected dry');
108 like($t->read_file('test.log'), qr|$p3:-|, 'log not found');
109
110 ###############################################################################