Changeset 935:25a4b2fdd3fb in nginx-tests


Ignore:
Timestamp:
05/24/16 09:58:26 (17 months ago)
Author:
Andrey Zelenkov <zelenkov@…>
Branch:
default
Message:

Tests: I/O timeout options introduced in Stream.

Some tests wait for unreachable response for 5 seconds
before timeout that lead to unnecessary delay.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/Test/Nginx/Stream.pm

    r875 r935  
    5959
    6060sub write {
    61         my ($self, $message) = @_;
     61        my ($self, $message, %extra) = @_;
    6262        my $s = $self->{_socket};
    6363
     
    6565
    6666        $s->blocking(0);
    67         while (IO::Select->new($s)->can_write(1.5)) {
     67        while (IO::Select->new($s)->can_write($extra{write_timeout} || 1.5)) {
    6868                my $n = $s->syswrite($message);
    6969                log_out(substr($message, 0, $n));
     
    8080
    8181sub read {
    82         my ($self) = @_;
     82        my ($self, %extra) = @_;
    8383        my ($s, $buf);
    8484
     
    8686
    8787        $s->blocking(0);
    88         if (IO::Select->new($s)->can_read(5)) {
     88        if (IO::Select->new($s)->can_read($extra{read_timeout} || 5)) {
    8989                $s->sysread($buf, 1024);
    9090        };
     
    104104                && $self->{_socket}->socktype() == &SOCK_DGRAM;
    105105
    106         $self->write($data);
     106        $self->write($data, %extra);
    107107
    108108        $data = '';
     
    110110                last if defined $read && --$read < 0;
    111111
    112                 my $buf = $self->read();
     112                my $buf = $self->read(%extra);
    113113                last unless defined $buf and length($buf);
    114114
  • stream_udp_limit_conn.t

    r925 r935  
    8888is($s->io('1'), '1', 'passed');
    8989
    90 is(dgram('127.0.0.1:8081')->io('1'), '', 'rejected same zone');
     90is(dgram('127.0.0.1:8081')->io('1', read_timeout => 0.1), '',
     91        'rejected same zone');
    9192is(dgram('127.0.0.1:8082')->io('1'), '1', 'passed different zone');
    9293is(dgram('127.0.0.1:8083')->io('1'), '1', 'passed same zone unlimited');
    9394
    94 is($s->io('2', read => 2), '12', 'long connection');
     95sleep 1;        # waiting for proxy_timeout to expire
     96
     97is($s->io('2', read => 2), '12', 'new connection after proxy_timeout');
    9598
    9699is(dgram('127.0.0.1:8081')->io('2', read => 2), '12', 'passed 2');
     
    99102
    100103is(dgram('127.0.0.1:8084')->io('1'), '1', 'passed proxy');
    101 is(dgram('127.0.0.1:8085')->io('1'), '', 'rejected proxy');
     104is(dgram('127.0.0.1:8085')->io('1', read_timeout => 0.1), '',
     105        'rejected proxy');
    102106
    103107###############################################################################
  • stream_udp_proxy.t

    r868 r935  
    6666
    6767my $s = dgram('127.0.0.1:8080');
    68 is($s->io('1', read => 1), '', 'proxy responses 0');
     68is($s->io('1', read => 1, read_timeout => 0.5), '', 'proxy responses 0');
    6969
    7070$s = dgram('127.0.0.1:8082');
    7171is($s->io('1'), '1', 'proxy responses 1');
    7272is($s->io('2', read => 2), '12', 'proxy responses 2');
    73 is($s->io('3', read => 3), '12', 'proxy responses 3');
     73is($s->io('3', read => 3, read_timeout => 0.5), '12', 'proxy responses 3');
    7474
    7575$s = dgram('127.0.0.1:8083');
Note: See TracChangeset for help on using the changeset viewer.