Mercurial > hg > nginx-tests
changeset 549:e4ff43e00d84
Tests: refactored least_conn test.
First, start long requests to busy both backends, and ensure that subsequent
consecutive requests are balanced to the only backend with zero connections.
This change aims to get rid of false negatives due timing issues.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 17 Apr 2015 17:54:06 +0300 |
parents | 56c3a8310076 |
children | a04b8b9537cd |
files | upstream_least_conn.t |
diffstat | 1 files changed, 8 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/upstream_least_conn.t Fri Apr 17 15:29:29 2015 +0300 +++ b/upstream_least_conn.t Fri Apr 17 17:54:06 2015 +0300 @@ -63,7 +63,14 @@ ############################################################################### is(many('/', 10), '8081: 5, 8082: 5', 'balanced'); -is(parallel('/w', 10), '8081: 1, 8082: 9', 'least conn'); + +my @sockets; +push(@sockets, http_get('/w', start => 1)); +push(@sockets, http_get('/w', start => 1)); + +select undef, undef, undef, 0.2; + +is(many('/w', 10), '8082: 10', 'least conn'); ############################################################################### @@ -81,25 +88,6 @@ return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; } -sub parallel { - my ($uri, $count, %opts) = @_; - my (@sockets, %ports); - - for (1 .. $count) { - push(@sockets, http_get($uri, start => 1)); - select undef, undef, undef, 0.2; - } - - for (1 .. $count) { - if (http_end(pop(@sockets)) =~ /X-Port: (\d+)/) { - $ports{$1} = 0 unless defined $ports{$1}; - $ports{$1}++; - } - } - - return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; -} - ############################################################################### sub http_daemon {