Mercurial > hg > nginx-tests
comparison upstream_least_conn.t @ 952:e9064d691790
Tests: converted tests to run in parallel.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Tue, 21 Jun 2016 16:39:13 +0300 |
parents | e4ff43e00d84 |
children | 882267679006 |
comparison
equal
deleted
inserted
replaced
951:9361c7eddfc1 | 952:e9064d691790 |
---|---|
35 http { | 35 http { |
36 %%TEST_GLOBALS_HTTP%% | 36 %%TEST_GLOBALS_HTTP%% |
37 | 37 |
38 upstream u { | 38 upstream u { |
39 least_conn; | 39 least_conn; |
40 server 127.0.0.1:8081; | 40 server 127.0.0.1:%%PORT_1%%; |
41 server 127.0.0.1:8082; | 41 server 127.0.0.1:%%PORT_2%%; |
42 } | 42 } |
43 | 43 |
44 server { | 44 server { |
45 listen 127.0.0.1:8080; | 45 listen 127.0.0.1:%%PORT_0%%; |
46 server_name localhost; | 46 server_name localhost; |
47 | 47 |
48 location / { | 48 location / { |
49 proxy_pass http://u; | 49 proxy_pass http://u; |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 EOF | 54 EOF |
55 | 55 |
56 $t->run_daemon(\&http_daemon, 8081); | 56 $t->run_daemon(\&http_daemon, port(1)); |
57 $t->run_daemon(\&http_daemon, 8082); | 57 $t->run_daemon(\&http_daemon, port(2)); |
58 $t->run(); | 58 $t->run(); |
59 | 59 |
60 $t->waitforsocket('127.0.0.1:8081'); | 60 $t->waitforsocket('127.0.0.1:' . port(1)); |
61 $t->waitforsocket('127.0.0.1:8082'); | 61 $t->waitforsocket('127.0.0.1:' . port(2)); |
62 | 62 |
63 ############################################################################### | 63 ############################################################################### |
64 | 64 |
65 is(many('/', 10), '8081: 5, 8082: 5', 'balanced'); | 65 my @ports = my ($port1, $port2) = (port(1), port(2)); |
66 | |
67 is(many('/', 10), "$port1: 5, $port2: 5", 'balanced'); | |
66 | 68 |
67 my @sockets; | 69 my @sockets; |
68 push(@sockets, http_get('/w', start => 1)); | 70 push(@sockets, http_get('/w', start => 1)); |
69 push(@sockets, http_get('/w', start => 1)); | 71 push(@sockets, http_get('/w', start => 1)); |
70 | 72 |
71 select undef, undef, undef, 0.2; | 73 select undef, undef, undef, 0.2; |
72 | 74 |
73 is(many('/w', 10), '8082: 10', 'least conn'); | 75 is(many('/w', 10), "$port2: 10", 'least conn'); |
74 | 76 |
75 ############################################################################### | 77 ############################################################################### |
76 | 78 |
77 sub many { | 79 sub many { |
78 my ($uri, $count) = @_; | 80 my ($uri, $count) = @_; |
83 $ports{$1} = 0 unless defined $ports{$1}; | 85 $ports{$1} = 0 unless defined $ports{$1}; |
84 $ports{$1}++; | 86 $ports{$1}++; |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; | 90 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
91 return join ', ', map { $_ . ": " . $ports{$_} } @keys; | |
89 } | 92 } |
90 | 93 |
91 ############################################################################### | 94 ############################################################################### |
92 | 95 |
93 sub http_daemon { | 96 sub http_daemon { |
115 last if (/^\x0d?\x0a?$/); | 118 last if (/^\x0d?\x0a?$/); |
116 } | 119 } |
117 | 120 |
118 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | 121 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; |
119 | 122 |
120 if ($uri eq '/w' && $port == 8081) { | 123 if ($uri eq '/w' && $port == port(1)) { |
121 Test::Nginx::log_core('||', "$port: sleep(2.5)"); | 124 Test::Nginx::log_core('||', "$port: sleep(2.5)"); |
122 select undef, undef, undef, 2.5; | 125 select undef, undef, undef, 2.5; |
123 } | 126 } |
124 | 127 |
125 Test::Nginx::log_core('||', "$port: response, 200"); | 128 Test::Nginx::log_core('||', "$port: response, 200"); |