comparison h2.t @ 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 196d33c2bb45
children 23418577df58
comparison
equal deleted inserted replaced
1064:6508aa1cf9cb 1065:2d4343a47c6d
24 24
25 select STDERR; $| = 1; 25 select STDERR; $| = 1;
26 select STDOUT; $| = 1; 26 select STDOUT; $| = 1;
27 27
28 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite charset gzip/) 28 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite charset gzip/)
29 ->plan(138); 29 ->plan(141);
30 30
31 # Some systems return EINVAL on zero writev iovcnt per POSIX, while others not 31 # Some systems return EINVAL on zero writev iovcnt per POSIX, while others not
32 32
33 $t->todo_alerts() if ($^O eq 'darwin' or $^O eq 'netbsd') 33 $t->todo_alerts() if ($^O eq 'darwin' or $^O eq 'netbsd')
34 and !$t->has_version('1.11.3'); 34 and !$t->has_version('1.11.3');
87 return 301 /; 87 return 301 /;
88 } 88 }
89 location /charset { 89 location /charset {
90 charset utf-8; 90 charset utf-8;
91 return 200; 91 return 200;
92 }
93 location /pid {
94 return 200 "pid $pid";
92 } 95 }
93 } 96 }
94 97
95 server { 98 server {
96 listen 127.0.0.1:8082 http2; 99 listen 127.0.0.1:8082 http2;
1076 $grace4->h2_body('TEST', { split => [ 12 ], abort => 1 }); 1079 $grace4->h2_body('TEST', { split => [ 12 ], abort => 1 });
1077 1080
1078 select undef, undef, undef, 1.1; 1081 select undef, undef, undef, 1.1;
1079 undef $grace4; 1082 undef $grace4;
1080 1083
1084 # GOAWAY without awaiting active streams, further streams ignored
1085
1086 SKIP: {
1087 skip 'win32', 3 if $^O eq 'MSWin32';
1088
1089 TODO: {
1090 local $TODO = 'not yet' unless $t->has_version('1.11.6');
1091
1092 $s = Test::Nginx::HTTP2->new(port(8080));
1093 $sid = $s->new_stream({ path => '/t1.html' });
1094 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
1095
1096 hup('/pid', 8081, $t);
1097
1098 $sid2 = $s->new_stream();
1099 $frames = $s->read(all => [{ sid => $sid2, fin => 0x4 }], wait => 0.5);
1100
1101 ($frame) = grep { $_->{type} eq 'HEADERS' } @$frames;
1102 is($frame, undef, 'GOAWAY with active stream - no new stream');
1103
1104 $frames = $s->read(all => [{ type => 'GOAWAY' }])
1105 unless grep { $_->{type} eq "GOAWAY" } @$frames;
1106
1107 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
1108 is($frame->{last_sid}, $sid, 'GOAWAY with active stream - last sid');
1109
1110 }
1111
1112 $s->h2_window(100, $sid);
1113 $s->h2_window(100);
1114 $frames = $s->read(all => [{ sid => $sid, fin => 0x1 }]);
1115
1116 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid } @$frames;
1117 $sum = eval join '+', map { $_->{length} } @data;
1118 is($sum, 81, 'GOAWAY with active stream - active stream DATA after GOAWAY');
1119
1120 }
1121
1081 # GOAWAY - force closing a connection by server with idle or active streams 1122 # GOAWAY - force closing a connection by server with idle or active streams
1082 1123
1124 $s = Test::Nginx::HTTP2->new();
1083 $sid = $s->new_stream(); 1125 $sid = $s->new_stream();
1084 $s->read(all => [{ sid => $sid, fin => 1 }]); 1126 $s->read(all => [{ sid => $sid, fin => 1 }]);
1085 1127
1086 my $active = Test::Nginx::HTTP2->new(port(8086)); 1128 my $active = Test::Nginx::HTTP2->new(port(8086));
1087 $sid = $active->new_stream({ path => '/t1.html' }); 1129 $sid = $active->new_stream({ path => '/t1.html' });
1118 1160
1119 like($out, $re, $name); 1161 like($out, $re, $name);
1120 } 1162 }
1121 } 1163 }
1122 1164
1165 sub hup {
1166 my ($uri, $port, $t) = @_;
1167
1168 my $sock = sub { IO::Socket::INET->new('127.0.0.1:' . port(shift)) };
1169 my ($pid) = http_get($uri, socket => $sock->($port)) =~ /pid (\d+)/;
1170
1171 kill 'HUP', $t->read_file('nginx.pid');
1172
1173 for (1 .. 20) {
1174 last if http_get($uri, socket => $sock->($port)) !~ /pid $pid/;
1175 select undef, undef, undef, 0.2;
1176 }
1177 }
1178
1123 ############################################################################### 1179 ###############################################################################