changeset 1065:2d4343a47c6d

Tests: more HTTP/2 GOAWAY tests with active stream.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 20 Oct 2016 18:52:37 +0300
parents 6508aa1cf9cb
children 23418577df58
files h2.t
diffstat 1 files changed, 57 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/h2.t
+++ b/h2.t
@@ -26,7 +26,7 @@ select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite charset gzip/)
-	->plan(138);
+	->plan(141);
 
 # Some systems return EINVAL on zero writev iovcnt per POSIX, while others not
 
@@ -90,6 +90,9 @@ http {
             charset utf-8;
             return 200;
         }
+        location /pid {
+            return 200 "pid $pid";
+        }
     }
 
     server {
@@ -1078,8 +1081,47 @@ my $grace4 = Test::Nginx::HTTP2->new(por
 select undef, undef, undef, 1.1;
 undef $grace4;
 
+# GOAWAY without awaiting active streams, further streams ignored
+
+SKIP: {
+skip 'win32', 3 if $^O eq 'MSWin32';
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
+$s = Test::Nginx::HTTP2->new(port(8080));
+$sid = $s->new_stream({ path => '/t1.html' });
+$s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
+
+hup('/pid', 8081, $t);
+
+$sid2 = $s->new_stream();
+$frames = $s->read(all => [{ sid => $sid2, fin => 0x4 }], wait => 0.5);
+
+($frame) = grep { $_->{type} eq 'HEADERS' } @$frames;
+is($frame, undef, 'GOAWAY with active stream - no new stream');
+
+$frames = $s->read(all => [{ type => 'GOAWAY' }])
+	unless grep { $_->{type} eq "GOAWAY" } @$frames;
+
+($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
+is($frame->{last_sid}, $sid, 'GOAWAY with active stream - last sid');
+
+}
+
+$s->h2_window(100, $sid);
+$s->h2_window(100);
+$frames = $s->read(all => [{ sid => $sid, fin => 0x1 }]);
+
+@data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid } @$frames;
+$sum = eval join '+', map { $_->{length} } @data;
+is($sum, 81, 'GOAWAY with active stream - active stream DATA after GOAWAY');
+
+}
+
 # GOAWAY - force closing a connection by server with idle or active streams
 
+$s = Test::Nginx::HTTP2->new();
 $sid = $s->new_stream();
 $s->read(all => [{ sid => $sid, fin => 1 }]);
 
@@ -1120,4 +1162,18 @@ sub gunzip_like {
 	}
 }
 
+sub hup {
+	my ($uri, $port, $t) = @_;
+
+	my $sock = sub { IO::Socket::INET->new('127.0.0.1:' . port(shift)) };
+	my ($pid) = http_get($uri, socket => $sock->($port)) =~ /pid (\d+)/;
+
+	kill 'HUP', $t->read_file('nginx.pid');
+
+	for (1 .. 20) {
+		last if http_get($uri, socket => $sock->($port)) !~ /pid $pid/;
+		select undef, undef, undef, 0.2;
+	}
+}
+
 ###############################################################################