Mercurial > hg > nginx-tests
comparison h2_keepalive.t @ 1694:3366128e526b
Tests: renamed test to better match HTTP/2 keepalive tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 01 Jun 2021 16:47:13 +0300 |
parents | h2_max_requests.t@5ac6efbe5552 |
children | 236d038dc04a |
comparison
equal
deleted
inserted
replaced
1693:5ac6efbe5552 | 1694:3366128e526b |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol, keepalive directives. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 use Socket qw(SOL_SOCKET SO_RCVBUF); | |
16 | |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
18 | |
19 use lib 'lib'; | |
20 use Test::Nginx; | |
21 use Test::Nginx::HTTP2; | |
22 | |
23 ############################################################################### | |
24 | |
25 select STDERR; $| = 1; | |
26 select STDOUT; $| = 1; | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http http_v2/) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080 http2 sndbuf=1m; | |
43 server_name localhost; | |
44 | |
45 keepalive_requests 2; | |
46 | |
47 location / { } | |
48 } | |
49 | |
50 server { | |
51 listen 127.0.0.1:8081 http2; | |
52 server_name localhost; | |
53 | |
54 keepalive_timeout 0; | |
55 | |
56 location / { } | |
57 } | |
58 | |
59 server { | |
60 listen 127.0.0.1:8082 http2; | |
61 server_name localhost; | |
62 | |
63 keepalive_time 1s; | |
64 | |
65 add_header X-Conn $connection_requests:$connection_time; | |
66 | |
67 location / { } | |
68 } | |
69 } | |
70 | |
71 EOF | |
72 | |
73 $t->write_file('index.html', 'SEE-THAT' x 50000); | |
74 $t->write_file('t.html', 'SEE-THAT'); | |
75 | |
76 $t->run()->plan(19); | |
77 | |
78 ############################################################################### | |
79 | |
80 my $s = Test::Nginx::HTTP2->new(); | |
81 | |
82 # to test lingering close, let full response settle down in send buffer space | |
83 # so that client additional data past server-side close would trigger TCP RST | |
84 | |
85 $s->{socket}->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024) or die $!; | |
86 $s->h2_settings(0, 0x4 => 2**20); | |
87 $s->h2_window(2**21); | |
88 | |
89 my $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]); | |
90 | |
91 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
92 is($frame->{headers}->{':status'}, 200, 'max requests'); | |
93 | |
94 $frames = $s->read(all => [{ type => 'GOAWAY' }], wait => 0.5) | |
95 unless grep { $_->{type} eq "GOAWAY" } @$frames; | |
96 | |
97 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
98 is($frame, undef, 'max requests - GOAWAY'); | |
99 | |
100 # max requests limited | |
101 | |
102 my $sid = $s->new_stream(); | |
103 | |
104 # wait server to finish and close socket if lingering close were disabled | |
105 | |
106 select undef, undef, undef, 0.1; | |
107 $s->h2_ping("SEE-THIS"); | |
108 | |
109 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
110 | |
111 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
112 is($frame->{headers}->{':status'}, 200, 'max requests limited'); | |
113 | |
114 my @data = grep { $_->{type} eq "DATA" } @$frames; | |
115 my $sum = eval join '+', map { $_->{length} } @data; | |
116 is($sum, 400000, 'max requests limited - all data received'); | |
117 | |
118 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
119 ok($frame, 'max requests limited - GOAWAY'); | |
120 is($frame->{last_sid}, $sid, 'max requests limited - GOAWAY last stream'); | |
121 | |
122 # keepalive_timeout 0 | |
123 | |
124 $s = Test::Nginx::HTTP2->new(port(8081)); | |
125 $sid = $s->new_stream({ path => '/t.html' }); | |
126 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
127 | |
128 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
129 is($frame->{headers}->{':status'}, 200, 'keepalive_timeout 0'); | |
130 | |
131 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
132 ok($frame, 'keepalive_timeout 0 - GOAWAY'); | |
133 | |
134 # keepalive_time | |
135 | |
136 $s = Test::Nginx::HTTP2->new(port(8082)); | |
137 $sid = $s->new_stream({ path => '/t.html' }); | |
138 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
139 | |
140 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
141 is($frame->{headers}->{':status'}, 200, 'keepalive time request'); | |
142 like($frame->{headers}->{'x-conn'}, qr/^1:0/, 'keepalive time variables'); | |
143 | |
144 $frames = $s->read(all => [{ type => 'GOAWAY' }], wait => 0.5); | |
145 | |
146 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
147 is($frame, undef, 'keepalive time - no GOAWAY yet'); | |
148 | |
149 select undef, undef, undef, 1.1; | |
150 | |
151 $sid = $s->new_stream({ path => '/t.html' }); | |
152 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
153 | |
154 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
155 is($frame->{headers}->{':status'}, 200, 'keepalive time request 2'); | |
156 like($frame->{headers}->{'x-conn'}, qr/^2:[^0]/, 'keepalive time variables 2'); | |
157 | |
158 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
159 ok($frame, 'keepalive time limit - GOAWAY'); | |
160 is($frame->{last_sid}, $sid, 'keepalive time limit - GOAWAY last stream'); | |
161 | |
162 # graceful shutdown in idle state | |
163 | |
164 $s = Test::Nginx::HTTP2->new(); | |
165 $s->{socket}->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024) or die $!; | |
166 $s->h2_settings(0, 0x4 => 2**20); | |
167 $s->h2_window(2**21); | |
168 | |
169 $sid = $s->new_stream(); | |
170 | |
171 # wait server to finish and close socket if lingering close were disabled | |
172 | |
173 select undef, undef, undef, 0.1; | |
174 | |
175 $t->reload(); | |
176 | |
177 select undef, undef, undef, 0.3; | |
178 | |
179 $s->h2_ping("SEE-THIS"); | |
180 | |
181 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
182 | |
183 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
184 is($frame->{headers}->{':status'}, 200, 'graceful shutdown in idle'); | |
185 | |
186 @data = grep { $_->{type} eq "DATA" } @$frames; | |
187 $sum = eval join '+', map { $_->{length} } @data; | |
188 is($sum, 400000, 'graceful shutdown in idle - all data received'); | |
189 | |
190 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
191 ok($frame, 'graceful shutdown in idle - GOAWAY'); | |
192 is($frame->{last_sid}, $sid, 'graceful shutdown in idle - GOAWAY last stream'); | |
193 | |
194 ############################################################################### |