Mercurial > hg > nginx-tests
diff upstream.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 | e7dc8f4d0a4b |
children | 882267679006 |
line wrap: on
line diff
--- a/upstream.t +++ b/upstream.t @@ -36,17 +36,17 @@ http { %%TEST_GLOBALS_HTTP%% upstream u { - server 127.0.0.1:8081 max_fails=3 fail_timeout=10s; - server 127.0.0.1:8082 max_fails=3 fail_timeout=10s; + server 127.0.0.1:%%PORT_1%% max_fails=3 fail_timeout=10s; + server 127.0.0.1:%%PORT_2%% max_fails=3 fail_timeout=10s; } upstream u2 { - server 127.0.0.1:8081 max_fails=3 fail_timeout=10s; - server 127.0.0.1:8082 max_fails=3 fail_timeout=10s; + server 127.0.0.1:%%PORT_1%% max_fails=3 fail_timeout=10s; + server 127.0.0.1:%%PORT_2%% max_fails=3 fail_timeout=10s; } server { - listen 127.0.0.1:8080; + listen 127.0.0.1:%%PORT_0%%; server_name localhost; location / { @@ -60,22 +60,24 @@ http { EOF -$t->run_daemon(\&http_daemon, 8081); -$t->run_daemon(\&http_daemon, 8082); +$t->run_daemon(\&http_daemon, port(1)); +$t->run_daemon(\&http_daemon, port(2)); $t->run(); -$t->waitforsocket('127.0.0.1:8081'); -$t->waitforsocket('127.0.0.1:8082'); +$t->waitforsocket('127.0.0.1:' . port(1)); +$t->waitforsocket('127.0.0.1:' . port(2)); ############################################################################### -is(many('/', 30), '8081: 15, 8082: 15', 'balanced'); +my @ports = my ($p1, $p2) = (port(1), port(2)); -# from 9 first requests to 8081, only 6 will be successful, +is(many('/', 30), "$p1: 15, $p2: 15", 'balanced'); + +# from 9 first requests to the first port, only 6 will be successful, # 3rd, 6th, and 9th requests will fail; after this the backend # will be considered down and won't be used till fail_timeout passes -is(many('/close', 30), '8081: 6, 8082: 24', 'failures'); +is(many('/close', 30), "$p1: 6, $p2: 24", 'failures'); SKIP: { skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE}; @@ -85,7 +87,7 @@ skip 'long test', 1 unless $ENV{TEST_NGI # delay added to make sure first 9 requests will take more than 1s; # note that the test is racy and may unexpectedly succeed -is(many('/close2', 30, delay => 0.2), '8081: 6, 8082: 24', 'failures delay'); +is(many('/close2', 30, delay => 0.2), "$p1: 6, $p2: 24", 'failures delay'); } @@ -104,7 +106,8 @@ sub many { select undef, undef, undef, $opts{delay} if $opts{delay}; } - return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; + my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; + return join ', ', map { $_ . ": " . $ports{$_} } @keys; } ############################################################################### @@ -137,7 +140,7 @@ sub http_daemon { $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; - if ($uri =~ 'close' && $port == 8081 && $count++ % 3 == 0) { + if ($uri =~ 'close' && $port == port(1) && $count++ % 3 == 0) { next; }