comparison h2_max_requests.t @ 1579:14eeaa39599d

Tests: HTTP/2 tests for lingering close.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 06 Jul 2020 15:38:51 +0300
parents 766bcbb632ee
children 3afb634f287d
comparison
equal deleted inserted replaced
1578:f55d25e08b3e 1579:14eeaa39599d
9 9
10 use warnings; 10 use warnings;
11 use strict; 11 use strict;
12 12
13 use Test::More; 13 use Test::More;
14
15 use Socket qw(SOL_SOCKET SO_RCVBUF);
14 16
15 BEGIN { use FindBin; chdir($FindBin::Bin); } 17 BEGIN { use FindBin; chdir($FindBin::Bin); }
16 18
17 use lib 'lib'; 19 use lib 'lib';
18 use Test::Nginx; 20 use Test::Nginx;
35 37
36 http { 38 http {
37 %%TEST_GLOBALS_HTTP%% 39 %%TEST_GLOBALS_HTTP%%
38 40
39 server { 41 server {
40 listen 127.0.0.1:8080 http2; 42 listen 127.0.0.1:8080 http2 sndbuf=1m;
41 server_name localhost; 43 server_name localhost;
42 44
43 http2_max_requests 2; 45 http2_max_requests 2;
44 46
45 location / { } 47 location / { }
46 } 48 }
47 } 49 }
48 50
49 EOF 51 EOF
50 52
51 $t->write_file('index.html', ''); 53 $t->write_file('index.html', 'SEE-THAT' x 50000);
52 $t->run()->plan(5); 54 $t->run()->plan(10);
53 55
54 ############################################################################### 56 ###############################################################################
55 57
56 my $s = Test::Nginx::HTTP2->new(); 58 my $s = Test::Nginx::HTTP2->new();
59
60 # to test lingering close, let full response settle down in send buffer space
61 # so that client additional data past server-side close would trigger TCP RST
62
63 $s->{socket}->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024) or die $!;
64 $s->h2_settings(0, 0x4 => 2**20);
65 $s->h2_window(2**21);
66
57 my $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]); 67 my $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]);
58 68
59 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 69 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
60 is($frame->{headers}->{':status'}, 200, 'max requests'); 70 is($frame->{headers}->{':status'}, 200, 'max requests');
61 71
66 is($frame, undef, 'max requests - GOAWAY'); 76 is($frame, undef, 'max requests - GOAWAY');
67 77
68 # max requests limited 78 # max requests limited
69 79
70 my $sid = $s->new_stream(); 80 my $sid = $s->new_stream();
81
82 # wait server to finish and close socket if lingering close were disabled
83
84 select undef, undef, undef, 0.1;
85 $s->h2_ping("SEE-THIS");
86
71 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); 87 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]);
72 88
73 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 89 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
74 is($frame->{headers}->{':status'}, 200, 'max requests limited'); 90 is($frame->{headers}->{':status'}, 200, 'max requests limited');
75 91
92 TODO: {
93 local $TODO = 'not yet' if $^O eq 'linux' or $^O eq 'freebsd'
94 and !$t->has_version('1.19.1');
95
96 my @data = grep { $_->{type} eq "DATA" } @$frames;
97 my $sum = eval join '+', map { $_->{length} } @data;
98 is($sum, 400000, 'max requests limited - all data received');
99
100 }
101
76 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; 102 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
77 ok($frame, 'max requests limited - GOAWAY'); 103 ok($frame, 'max requests limited - GOAWAY');
78 is($frame->{last_sid}, $sid, 'max requests limited - GOAWAY last stream'); 104 is($frame->{last_sid}, $sid, 'max requests limited - GOAWAY last stream');
79 105
106 # graceful shutdown in idle state
107
108 $s = Test::Nginx::HTTP2->new();
109 $s->{socket}->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024) or die $!;
110 $s->h2_settings(0, 0x4 => 2**20);
111 $s->h2_window(2**21);
112
113 $sid = $s->new_stream();
114
115 # wait server to finish and close socket if lingering close were disabled
116
117 select undef, undef, undef, 0.1;
118
119 $t->reload();
120
121 select undef, undef, undef, 0.3;
122
123 $s->h2_ping("SEE-THIS");
124
125 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]);
126
127 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
128 is($frame->{headers}->{':status'}, 200, 'graceful shutdown in idle');
129
130 TODO: {
131 local $TODO = 'not yet' if $^O eq 'linux' or $^O eq 'freebsd'
132 and !$t->has_version('1.19.1');
133
134 my @data = grep { $_->{type} eq "DATA" } @$frames;
135 my $sum = eval join '+', map { $_->{length} } @data;
136 is($sum, 400000, 'graceful shutdown in idle - all data received');
137
138 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
139 ok($frame, 'graceful shutdown in idle - GOAWAY');
140 is($frame->{last_sid}, $sid, 'graceful shutdown in idle - GOAWAY last stream');
141
142 }
143
80 ############################################################################### 144 ###############################################################################