comparison stream_limit_conn_complex.t @ 966:3ac72d59430b

Tests: stream limit_conn tests with complex value.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 05 Jul 2016 20:33:53 +0300
parents
children 882267679006
comparison
equal deleted inserted replaced
965:75ad4a978306 966:3ac72d59430b
1 #!/usr/bin/perl
2
3 # (C) Andrey Zelenkov
4 # (C) Nginx, Inc.
5
6 # Tests for stream limit_conn module.
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
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http stream stream_limit_conn shmem/)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 daemon off;
31
32 events {
33 }
34
35 stream {
36 limit_conn_zone $binary_remote_addr$server_port zone=zone:1m;
37
38 server {
39 listen 127.0.0.1:%%PORT_0%%;
40 proxy_pass 127.0.0.1:%%PORT_4%%;
41 limit_conn zone 1;
42 }
43
44 server {
45 listen 127.0.0.1:%%PORT_1%%;
46 proxy_pass 127.0.0.1:%%PORT_4%%;
47 limit_conn zone 1;
48 }
49 }
50
51 http {
52 %%TEST_GLOBALS_HTTP%%
53
54 server {
55 listen 127.0.0.1:%%PORT_4%%;
56 server_name localhost;
57
58 location / { }
59 }
60 }
61
62 EOF
63
64 $t->write_file('index.html', '');
65 $t->try_run('no stream limit_conn with complex value')->plan(4);
66
67 ###############################################################################
68
69 like(get(port(0)), qr/200 OK/, 'passed');
70
71 my $s = http(<<EOF, start => 1, sleep => 0.2);
72 GET / HTTP/1.0
73 EOF
74
75 ok($s, 'long connection');
76
77 is(get(port(0)), undef, 'rejected same key');
78 like(get(port(1)), qr/200 OK/, 'passed different key');
79
80 ###############################################################################
81
82 sub get {
83 my $port = shift;
84
85 my $s = IO::Socket::INET->new(
86 Proto => 'tcp',
87 PeerAddr => "127.0.0.1:$port"
88 )
89 or die "Can't connect to nginx: $!\n";
90
91 my $r = http_get('/', socket => $s);
92 if (!$r) {
93 $r = undef;
94 }
95
96 return $r;
97 }
98
99 ###############################################################################