Mercurial > hg > nginx-tests
changeset 1105:a073a545413d
Tests: stream upstream tests for fast peer recovery.
Now, a peer is considered recovered after a successful TCP connection is
established to it. See 54cf51c4f07a for details.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 29 Dec 2016 19:30:29 +0300 |
parents | b3d5a2f8a00b |
children | 4b0b10e39a08 |
files | stream_upstream.t |
diffstat | 1 files changed, 37 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/stream_upstream.t Thu Dec 29 18:54:04 2016 +0300 +++ b/stream_upstream.t Thu Dec 29 19:30:29 2016 +0300 @@ -57,7 +57,7 @@ } upstream u4 { - server 127.0.0.1:8086; + server 127.0.0.1:8086 fail_timeout=1s; server 127.0.0.1:8084 backup; } @@ -89,7 +89,7 @@ $t->run_daemon(\&stream_daemon, port(8084)); $t->run_daemon(\&stream_daemon, port(8085)); -$t->try_run('no stream access_log')->plan(5); +$t->try_run('no stream access_log')->plan(6); $t->waitforsocket('127.0.0.1:' . port(8084)); $t->waitforsocket('127.0.0.1:' . port(8085)); @@ -103,6 +103,17 @@ is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight'); is(many(30, port(8083)), "$port4: 30", 'backup'); +$t->run_daemon(\&stream_daemon, port(8086)); +$t->waitforsocket('127.0.0.1:' . port(8086)); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.11.8'); + +sleep 2; # wait till fail_timeout passes +is(parallel(30, port(8083)), "$port6: 30", 'recovery'); + +} + $t->stop(); like($t->read_file('u.log'), qr/127.0.0.1:$port6, 127.0.0.1:$port4!0, 1!0, 4/, @@ -125,6 +136,28 @@ return join ', ', map { $_ . ": " . $ports{$_} } @keys; } +sub parallel { + my ($count, $port) = @_; + my (%ports, @s); + + for (1 .. $count) { + my $s = stream("127.0.0.1:$port"); + $s->write('keep'); + $s->read(); + push @s, $s; + } + + for (1 .. $count) { + if ((pop @s)->io('.') =~ /(\d+)/) { + $ports{$1} = 0 unless defined $ports{$1}; + $ports{$1}++; + } + } + + my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; + return join ', ', map { $_ . ": " . $ports{$_} } @keys; +} + ############################################################################### sub stream_daemon { @@ -167,13 +200,14 @@ log2i("$client $buffer"); + my $close = $buffer ne 'keep'; $buffer = $client->sockport(); log2o("$client $buffer"); $client->syswrite($buffer); - return 1; + return $close; } sub log2i { Test::Nginx::log_core('|| <<', @_); }