# HG changeset patch # User Sergey Kandaurov # Date 1429282446 -10800 # Node ID e4ff43e00d84d0ae3702dec30d51e3684052b679 # Parent 56c3a8310076cdb8a3c46850ffd725d6e95a0402 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. diff --git a/upstream_least_conn.t b/upstream_least_conn.t --- a/upstream_least_conn.t +++ b/upstream_least_conn.t @@ -63,7 +63,14 @@ EOF ############################################################################### 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 @@ sub many { 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 {