comparison h2.t @ 974:882267679006

Tests: simplified parallel modifications in tests. Mail tests were simplified in c227348453db.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 12 Jul 2016 17:39:03 +0300
parents e9064d691790
children 892737e9fd31
comparison
equal deleted inserted replaced
973:7d7aef8b9f3a 974:882267679006
42 42
43 http { 43 http {
44 %%TEST_GLOBALS_HTTP%% 44 %%TEST_GLOBALS_HTTP%%
45 45
46 server { 46 server {
47 listen 127.0.0.1:%%PORT_0%% http2; 47 listen 127.0.0.1:8080 http2;
48 listen 127.0.0.1:%%PORT_1%%; 48 listen 127.0.0.1:8081;
49 server_name localhost; 49 server_name localhost;
50 50
51 location / { 51 location / {
52 add_header X-Header X-Foo; 52 add_header X-Header X-Foo;
53 add_header X-Sent-Foo $http_x_foo; 53 add_header X-Sent-Foo $http_x_foo;
89 return 200; 89 return 200;
90 } 90 }
91 } 91 }
92 92
93 server { 93 server {
94 listen 127.0.0.1:%%PORT_2%% http2; 94 listen 127.0.0.1:8082 http2;
95 server_name localhost; 95 server_name localhost;
96 return 200 first; 96 return 200 first;
97 } 97 }
98 98
99 server { 99 server {
100 listen 127.0.0.1:%%PORT_2%% http2; 100 listen 127.0.0.1:8082 http2;
101 server_name localhost2; 101 server_name localhost2;
102 return 200 second; 102 return 200 second;
103 } 103 }
104 104
105 server { 105 server {
106 listen 127.0.0.1:%%PORT_3%% http2; 106 listen 127.0.0.1:8083 http2;
107 server_name localhost; 107 server_name localhost;
108 108
109 http2_max_concurrent_streams 1; 109 http2_max_concurrent_streams 1;
110 } 110 }
111 111
112 server { 112 server {
113 listen 127.0.0.1:%%PORT_4%% http2; 113 listen 127.0.0.1:8084 http2;
114 server_name localhost; 114 server_name localhost;
115 115
116 http2_recv_timeout 1s; 116 http2_recv_timeout 1s;
117 client_header_timeout 1s; 117 client_header_timeout 1s;
118 send_timeout 1s; 118 send_timeout 1s;
119 } 119 }
120 120
121 server { 121 server {
122 listen 127.0.0.1:%%PORT_5%% http2; 122 listen 127.0.0.1:8085 http2;
123 server_name localhost; 123 server_name localhost;
124 124
125 http2_idle_timeout 1s; 125 http2_idle_timeout 1s;
126 client_body_timeout 1s; 126 client_body_timeout 1s;
127 127
128 location /proxy2/ { 128 location /proxy2/ {
129 add_header X-Body $request_body; 129 add_header X-Body $request_body;
130 proxy_pass http://127.0.0.1:%%PORT_1%%/; 130 proxy_pass http://127.0.0.1:8081/;
131 } 131 }
132 } 132 }
133 133
134 server { 134 server {
135 listen 127.0.0.1:%%PORT_6%% http2; 135 listen 127.0.0.1:8086 http2;
136 server_name localhost; 136 server_name localhost;
137 137
138 send_timeout 1s; 138 send_timeout 1s;
139 } 139 }
140 140
141 server { 141 server {
142 listen 127.0.0.1:%%PORT_7%% http2; 142 listen 127.0.0.1:8087 http2;
143 server_name localhost; 143 server_name localhost;
144 144
145 client_header_timeout 1s; 145 client_header_timeout 1s;
146 client_body_timeout 1s; 146 client_body_timeout 1s;
147 147
148 location /proxy/ { 148 location /proxy/ {
149 proxy_pass http://127.0.0.1:%%PORT_1%%/; 149 proxy_pass http://127.0.0.1:8081/;
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 EOF 154 EOF
185 185
186 } 186 }
187 187
188 # SETTINGS 188 # SETTINGS
189 189
190 my $s = Test::Nginx::HTTP2->new(port(0), pure => 1); 190 my $s = Test::Nginx::HTTP2->new(port(8080), pure => 1);
191 my $frames = $s->read(all => [ 191 my $frames = $s->read(all => [
192 { type => 'WINDOW_UPDATE' }, 192 { type => 'WINDOW_UPDATE' },
193 { type => 'SETTINGS'} 193 { type => 'SETTINGS'}
194 ]); 194 ]);
195 195
227 # timeouts 227 # timeouts
228 228
229 SKIP: { 229 SKIP: {
230 skip 'long tests', 6 unless $ENV{TEST_NGINX_UNSAFE}; 230 skip 'long tests', 6 unless $ENV{TEST_NGINX_UNSAFE};
231 231
232 push my @s, Test::Nginx::HTTP2->new(port(4), pure => 1); 232 push my @s, Test::Nginx::HTTP2->new(port(8084), pure => 1);
233 push @s, Test::Nginx::HTTP2->new(port(4), pure => 1); 233 push @s, Test::Nginx::HTTP2->new(port(8084), pure => 1);
234 $s[-1]->h2_ping('SEE-THIS'); 234 $s[-1]->h2_ping('SEE-THIS');
235 push @s, Test::Nginx::HTTP2->new(port(5), pure => 1); 235 push @s, Test::Nginx::HTTP2->new(port(8085), pure => 1);
236 push @s, Test::Nginx::HTTP2->new(port(5), pure => 1); 236 push @s, Test::Nginx::HTTP2->new(port(8085), pure => 1);
237 $s[-1]->h2_ping('SEE-THIS'); 237 $s[-1]->h2_ping('SEE-THIS');
238 238
239 select undef, undef, undef, 2.1; 239 select undef, undef, undef, 2.1;
240 240
241 $frames = (shift @s)->read(all => [{ type => "GOAWAY" }]); 241 $frames = (shift @s)->read(all => [{ type => "GOAWAY" }]);
495 $sid = $s->new_stream({ path => '/return301_relative' }); 495 $sid = $s->new_stream({ path => '/return301_relative' });
496 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); 496 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
497 497
498 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 498 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
499 is($frame->{headers}->{':status'}, 301, 'return 301 relative - status'); 499 is($frame->{headers}->{':status'}, 301, 'return 301 relative - status');
500 is($frame->{headers}->{'location'}, 'http://localhost:' . port(0) . '/', 500 is($frame->{headers}->{'location'}, 'http://localhost:' . port(8080) . '/',
501 'return 301 relative - location'); 501 'return 301 relative - location');
502 502
503 # return 301 with relative URI and ':authority' request header field 503 # return 301 with relative URI and ':authority' request header field
504 504
505 $s = Test::Nginx::HTTP2->new(); 505 $s = Test::Nginx::HTTP2->new();
511 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); 511 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
512 512
513 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 513 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
514 is($frame->{headers}->{':status'}, 301, 514 is($frame->{headers}->{':status'}, 301,
515 'return 301 relative - authority - status'); 515 'return 301 relative - authority - status');
516 is($frame->{headers}->{'location'}, 'http://localhost:' . port(0) . '/', 516 is($frame->{headers}->{'location'}, 'http://localhost:' . port(8080) . '/',
517 'return 301 relative - authority - location'); 517 'return 301 relative - authority - location');
518 518
519 # return 301 with relative URI and 'host' request header field 519 # return 301 with relative URI and 'host' request header field
520 520
521 $s = Test::Nginx::HTTP2->new(); 521 $s = Test::Nginx::HTTP2->new();
527 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); 527 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
528 528
529 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 529 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
530 is($frame->{headers}->{':status'}, 301, 530 is($frame->{headers}->{':status'}, 301,
531 'return 301 relative - host - status'); 531 'return 301 relative - host - status');
532 is($frame->{headers}->{'location'}, 'http://localhost:' . port(0) . '/', 532 is($frame->{headers}->{'location'}, 'http://localhost:' . port(8080) . '/',
533 'return 301 relative - host - location'); 533 'return 301 relative - host - location');
534 534
535 # virtual host 535 # virtual host
536 536
537 $s = Test::Nginx::HTTP2->new(port(2)); 537 $s = Test::Nginx::HTTP2->new(port(8082));
538 $sid = $s->new_stream({ headers => [ 538 $sid = $s->new_stream({ headers => [
539 { name => ':method', value => 'GET', mode => 0 }, 539 { name => ':method', value => 'GET', mode => 0 },
540 { name => ':scheme', value => 'http', mode => 0 }, 540 { name => ':scheme', value => 'http', mode => 0 },
541 { name => ':path', value => '/', mode => 0 }, 541 { name => ':path', value => '/', mode => 0 },
542 { name => 'host', value => 'localhost', mode => 2 }]}); 542 { name => 'host', value => 'localhost', mode => 2 }]});
624 # the rest of frame is received after client header timeout 624 # the rest of frame is received after client header timeout
625 625
626 TODO: { 626 TODO: {
627 local $TODO = 'not yet' unless $t->has_version('1.9.12'); 627 local $TODO = 'not yet' unless $t->has_version('1.9.12');
628 628
629 $s = Test::Nginx::HTTP2->new(port(7)); 629 $s = Test::Nginx::HTTP2->new(port(8087));
630 $sid = $s->new_stream({ path => '/t2.html', split => [35], 630 $sid = $s->new_stream({ path => '/t2.html', split => [35],
631 split_delay => 2.1 }); 631 split_delay => 2.1 });
632 $frames = $s->read(all => [{ type => 'RST_STREAM' }]); 632 $frames = $s->read(all => [{ type => 'RST_STREAM' }]);
633 633
634 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; 634 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
646 # partial request body data frame received, the rest is after body timeout 646 # partial request body data frame received, the rest is after body timeout
647 647
648 TODO: { 648 TODO: {
649 local $TODO = 'not yet' unless $t->has_version('1.9.12'); 649 local $TODO = 'not yet' unless $t->has_version('1.9.12');
650 650
651 $s = Test::Nginx::HTTP2->new(port(7)); 651 $s = Test::Nginx::HTTP2->new(port(8087));
652 $sid = $s->new_stream({ path => '/proxy/t2.html', body_more => 1 }); 652 $sid = $s->new_stream({ path => '/proxy/t2.html', body_more => 1 });
653 $s->h2_body('TEST', { split => [10], split_delay => 2.1 }); 653 $s->h2_body('TEST', { split => [10], split_delay => 2.1 });
654 $frames = $s->read(all => [{ type => 'RST_STREAM' }]); 654 $frames = $s->read(all => [{ type => 'RST_STREAM' }]);
655 655
656 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; 656 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
827 827
828 } 828 }
829 829
830 # write event send timeout 830 # write event send timeout
831 831
832 $s = Test::Nginx::HTTP2->new(port(6)); 832 $s = Test::Nginx::HTTP2->new(port(8086));
833 $sid = $s->new_stream({ path => '/tbig.html' }); 833 $sid = $s->new_stream({ path => '/tbig.html' });
834 $s->h2_window(2**30, $sid); 834 $s->h2_window(2**30, $sid);
835 $s->h2_window(2**30); 835 $s->h2_window(2**30);
836 836
837 select undef, undef, undef, 2.1; 837 select undef, undef, undef, 2.1;
914 $sum = eval join '+', map { $_->{length} } @data; 914 $sum = eval join '+', map { $_->{length} } @data;
915 is($sum, 2**16 + 80, 'multiple - stream2 full data'); 915 is($sum, 2**16 + 80, 'multiple - stream2 full data');
916 916
917 # http2_max_concurrent_streams 917 # http2_max_concurrent_streams
918 918
919 $s = Test::Nginx::HTTP2->new(port(3), pure => 1); 919 $s = Test::Nginx::HTTP2->new(port(8083), pure => 1);
920 $frames = $s->read(all => [{ type => 'SETTINGS' }]); 920 $frames = $s->read(all => [{ type => 'SETTINGS' }]);
921 921
922 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames; 922 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames;
923 is($frame->{3}, 1, 'http2_max_concurrent_streams SETTINGS'); 923 is($frame->{3}, 1, 'http2_max_concurrent_streams SETTINGS');
924 924
992 992
993 # some invalid cases below 993 # some invalid cases below
994 994
995 # invalid connection preface 995 # invalid connection preface
996 996
997 $s = Test::Nginx::HTTP2->new(port(0), preface => 'x' x 16, pure => 1); 997 $s = Test::Nginx::HTTP2->new(port(8080), preface => 'x' x 16, pure => 1);
998 $frames = $s->read(all => [{ type => 'GOAWAY' }]); 998 $frames = $s->read(all => [{ type => 'GOAWAY' }]);
999 999
1000 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; 1000 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
1001 ok($frame, 'invalid preface - GOAWAY frame'); 1001 ok($frame, 'invalid preface - GOAWAY frame');
1002 is($frame->{code}, 1, 'invalid preface - error code'); 1002 is($frame->{code}, 1, 'invalid preface - error code');
1003 1003
1004 my $preface = 'PRI * HTTP/2.0' . CRLF . CRLF . 'x' x 8; 1004 my $preface = 'PRI * HTTP/2.0' . CRLF . CRLF . 'x' x 8;
1005 $s = Test::Nginx::HTTP2->new(port(0), preface => $preface, pure => 1); 1005 $s = Test::Nginx::HTTP2->new(port(8080), preface => $preface, pure => 1);
1006 $frames = $s->read(all => [{ type => 'GOAWAY' }]); 1006 $frames = $s->read(all => [{ type => 'GOAWAY' }]);
1007 1007
1008 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; 1008 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
1009 ok($frame, 'invalid preface 2 - GOAWAY frame'); 1009 ok($frame, 'invalid preface 2 - GOAWAY frame');
1010 is($frame->{code}, 1, 'invalid preface 2 - error code'); 1010 is($frame->{code}, 1, 'invalid preface 2 - error code');
1071 $sid = $s->new_stream(); 1071 $sid = $s->new_stream();
1072 $s->read(all => [{ sid => $sid, fin => 1 }]); 1072 $s->read(all => [{ sid => $sid, fin => 1 }]);
1073 1073
1074 # graceful shutdown with stream waiting on HEADERS payload 1074 # graceful shutdown with stream waiting on HEADERS payload
1075 1075
1076 my $grace = Test::Nginx::HTTP2->new(port(4)); 1076 my $grace = Test::Nginx::HTTP2->new(port(8084));
1077 $grace->new_stream({ split => [ 9 ], abort => 1 }); 1077 $grace->new_stream({ split => [ 9 ], abort => 1 });
1078 1078
1079 # graceful shutdown with stream waiting on WINDOW_UPDATE 1079 # graceful shutdown with stream waiting on WINDOW_UPDATE
1080 1080
1081 my $grace2 = Test::Nginx::HTTP2->new(port(4)); 1081 my $grace2 = Test::Nginx::HTTP2->new(port(8084));
1082 $sid = $grace2->new_stream({ path => '/t1.html' }); 1082 $sid = $grace2->new_stream({ path => '/t1.html' });
1083 $grace2->read(all => [{ sid => $sid, length => 2**16 - 1 }]); 1083 $grace2->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
1084 1084
1085 # graceful shutdown waiting on incomplete request body DATA frames 1085 # graceful shutdown waiting on incomplete request body DATA frames
1086 1086
1087 my $grace3 = Test::Nginx::HTTP2->new(port(5)); 1087 my $grace3 = Test::Nginx::HTTP2->new(port(8085));
1088 $sid = $grace3->new_stream({ path => '/proxy2/t2.html', body_more => 1 }); 1088 $sid = $grace3->new_stream({ path => '/proxy2/t2.html', body_more => 1 });
1089 $grace3->h2_body('TEST', { body_more => 1 }); 1089 $grace3->h2_body('TEST', { body_more => 1 });
1090 1090
1091 # partial request body data frame with connection close after body timeout 1091 # partial request body data frame with connection close after body timeout
1092 1092
1093 my $grace4 = Test::Nginx::HTTP2->new(port(7)); 1093 my $grace4 = Test::Nginx::HTTP2->new(port(8087));
1094 $sid = $grace4->new_stream({ path => '/proxy/t2.html', body_more => 1 }); 1094 $sid = $grace4->new_stream({ path => '/proxy/t2.html', body_more => 1 });
1095 $grace4->h2_body('TEST', { split => [ 12 ], abort => 1 }); 1095 $grace4->h2_body('TEST', { split => [ 12 ], abort => 1 });
1096 1096
1097 select undef, undef, undef, 1.1; 1097 select undef, undef, undef, 1.1;
1098 undef $grace4; 1098 undef $grace4;