Mercurial > hg > nginx-tests
comparison grpc.t @ 1318:6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 05 Apr 2018 17:16:31 +0300 |
parents | 6f95c0ed2335 |
children | 3b30e97acdcb |
comparison
equal
deleted
inserted
replaced
1317:a05f377bf0ca | 1318:6de2a27af2d3 |
---|---|
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 EOF | 92 EOF |
93 | 93 |
94 $t->try_run('no grpc')->plan(97); | 94 $t->try_run('no grpc')->plan(100); |
95 | 95 |
96 ############################################################################### | 96 ############################################################################### |
97 | 97 |
98 my $p = port(8081); | 98 my $p = port(8081); |
99 my $f = grpc(); | 99 my $f = grpc(); |
354 is($frame->{length}, 5, 'flow control - rest length'); | 354 is($frame->{length}, 5, 'flow control - rest length'); |
355 is($frame->{flags}, 1, 'flow control - rest flags'); | 355 is($frame->{flags}, 1, 'flow control - rest flags'); |
356 | 356 |
357 $f->{http_end}(); | 357 $f->{http_end}(); |
358 | 358 |
359 # preserve output | |
360 | |
361 $f->{http_start}('/Preserve'); | |
362 $f->{data}('Hello'); | |
363 $frames = $f->{http_pres}(); | |
364 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
365 is($frame->{flags}, 4, 'preserve - HEADERS'); | |
366 | |
367 my @data = grep { $_->{type} eq "DATA" } @$frames; | |
368 $sum = eval join '+', map { $_->{length} } @data; | |
369 is($sum, 163840, 'preserve - DATA'); | |
370 | |
371 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
372 is($frame->{flags}, 5, 'preserve - trailers'); | |
373 | |
359 # DATA padding | 374 # DATA padding |
360 | 375 |
361 $f->{http_start}('/SayPadding'); | 376 $f->{http_start}('/SayPadding'); |
362 $f->{data}('Hello'); | 377 $f->{data}('Hello'); |
363 $frames = $f->{http_end}(body_padding => 42); | 378 $frames = $f->{http_end}(body_padding => 42); |
420 $f->{http_end}(); | 435 $f->{http_end}(); |
421 | 436 |
422 ############################################################################### | 437 ############################################################################### |
423 | 438 |
424 sub grpc { | 439 sub grpc { |
425 my ($server, $client, $f, $s, $c, $sid, $uri); | 440 my ($server, $client, $f, $s, $c, $sid, $csid, $uri); |
426 my $n = 0; | 441 my $n = 0; |
427 | 442 |
428 $server = IO::Socket::INET->new( | 443 $server = IO::Socket::INET->new( |
429 Proto => 'tcp', | 444 Proto => 'tcp', |
430 LocalHost => '127.0.0.1', | 445 LocalHost => '127.0.0.1', |
437 $f->{http_start} = sub { | 452 $f->{http_start} = sub { |
438 ($uri, my %extra) = @_; | 453 ($uri, my %extra) = @_; |
439 my $body_more = 1 if $uri !~ /LongHeader/; | 454 my $body_more = 1 if $uri !~ /LongHeader/; |
440 my $meth = $extra{method} || 'POST'; | 455 my $meth = $extra{method} || 'POST'; |
441 $s = Test::Nginx::HTTP2->new() if !defined $s; | 456 $s = Test::Nginx::HTTP2->new() if !defined $s; |
442 $s->new_stream({ body_more => $body_more, headers => [ | 457 $csid = $s->new_stream({ body_more => $body_more, headers => [ |
443 { name => ':method', value => $meth, mode => !!$meth }, | 458 { name => ':method', value => $meth, mode => !!$meth }, |
444 { name => ':scheme', value => 'http', mode => 0 }, | 459 { name => ':scheme', value => 'http', mode => 0 }, |
445 { name => ':path', value => $uri, }, | 460 { name => ':path', value => $uri, }, |
446 { name => ':authority', value => 'localhost' }, | 461 { name => ':authority', value => 'localhost' }, |
447 { name => 'content-type', value => 'application/grpc' }, | 462 { name => 'content-type', value => 'application/grpc' }, |
496 { name => 'x-connection', value => $n, | 511 { name => 'x-connection', value => $n, |
497 mode => 2, huff => 1 }, | 512 mode => 2, huff => 1 }, |
498 ]}, $sid); | 513 ]}, $sid); |
499 $c->h2_body('Hello world', { body_more => 1, | 514 $c->h2_body('Hello world', { body_more => 1, |
500 body_padding => $extra{body_padding} }); | 515 body_padding => $extra{body_padding} }); |
516 $c->new_stream({ headers => [ | |
517 { name => 'grpc-status', value => '0', | |
518 mode => 2, huff => 1 }, | |
519 { name => 'grpc-message', value => '', | |
520 mode => 2, huff => 1 }, | |
521 ]}, $sid); | |
522 | |
523 return $s->read(all => [{ fin => 1 }]); | |
524 }; | |
525 $f->{http_pres} = sub { | |
526 my (%extra) = @_; | |
527 $c->new_stream({ body_more => 1, %extra, headers => [ | |
528 { name => ':status', value => '200', | |
529 mode => $extra{mode} || 0 }, | |
530 { name => 'content-type', value => 'application/grpc', | |
531 mode => $extra{mode} || 1, huff => 1 }, | |
532 { name => 'x-connection', value => $n, | |
533 mode => 2, huff => 1 }, | |
534 ]}, $sid); | |
535 for (1 .. 20) { | |
536 $c->h2_body(sprintf('Hello %02d', $_) x 1024, { | |
537 body_more => 1, | |
538 body_padding => $extra{body_padding} }); | |
539 $c->h2_ping("PING"); | |
540 } | |
541 # reopen window | |
542 $s->h2_window(2**24); | |
543 $s->h2_window(2**24, $csid); | |
501 $c->new_stream({ headers => [ | 544 $c->new_stream({ headers => [ |
502 { name => 'grpc-status', value => '0', | 545 { name => 'grpc-status', value => '0', |
503 mode => 2, huff => 1 }, | 546 mode => 2, huff => 1 }, |
504 { name => 'grpc-message', value => '', | 547 { name => 'grpc-message', value => '', |
505 mode => 2, huff => 1 }, | 548 mode => 2, huff => 1 }, |