comparison grpc.t @ 1564:fe938b5daf80

Tests: more grpc tests with discarded request body.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 28 Apr 2020 18:44:29 +0300
parents 144c6ce732e4
children 8aede7babd9a
comparison
equal deleted inserted replaced
1563:c1d167a13c24 1564:fe938b5daf80
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) 26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/)
27 ->has(qw/upstream_keepalive/)->plan(105); 27 ->has(qw/upstream_keepalive/)->plan(109);
28 28
29 $t->write_file_expand('nginx.conf', <<'EOF'); 29 $t->write_file_expand('nginx.conf', <<'EOF');
30 30
31 %%TEST_GLOBALS%% 31 %%TEST_GLOBALS%%
32 32
459 $frames = $f->{http_start}('/', method => 'HEAD'); 459 $frames = $f->{http_start}('/', method => 'HEAD');
460 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 460 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
461 is($frame->{headers}{':method'}, 'HEAD', 'method head'); 461 is($frame->{headers}{':method'}, 'HEAD', 'method head');
462 $f->{data}('Hello'); 462 $f->{data}('Hello');
463 $f->{http_end}(); 463 $f->{http_end}();
464
465 TODO: {
466 local $TODO = 'not yet' unless $t->has_version('1.19.0');
467
468 # receiving END_STREAM followed by WINDOW_UPDATE on incomplete request body
469
470 $f->{http_start}('/Discard_WU');
471 $frames = $f->{discard}();
472 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
473 is($frame->{flags}, 5, 'discard WINDOW_UPDATE - trailers');
474
475 # receiving END_STREAM followed by RST_STREAM NO_ERROR
476
477 $f->{http_start}('/Discard_NE');
478 $frames = $f->{discard}();
479 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
480 is($frame->{flags}, 5, 'discard NO_ERROR - trailers');
481
482 }
483
484 # receiving END_STREAM followed by several RST_STREAM NO_ERROR
485
486 $f->{http_start}('/Discard_NE3');
487 $frames = $f->{discard}();
488 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
489 is($frame->{flags}, undef, 'discard NO_ERROR many - no trailers');
490
491 # receiving END_STREAM followed by RST_STREAM CANCEL
492
493 $f->{http_start}('/Discard_CNL');
494 $frames = $f->{discard}();
495 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
496 is($frame->{flags}, undef, 'discard CANCEL - no trailers');
464 497
465 ############################################################################### 498 ###############################################################################
466 499
467 sub grpc { 500 sub grpc {
468 my ($server, $client, $f, $s, $c, $sid, $csid, $uri); 501 my ($server, $client, $f, $s, $c, $sid, $csid, $uri);
648 mode => 2, huff => 1 }, 681 mode => 2, huff => 1 },
649 ]}, $sid); 682 ]}, $sid);
650 683
651 return $s->read(all => [{ fin => 1 }]); 684 return $s->read(all => [{ fin => 1 }]);
652 }; 685 };
686 $f->{discard} = sub {
687 my (%extra) = @_;
688 $c->new_stream({ body_more => 1, %extra, headers => [
689 { name => ':status', value => '200',
690 mode => $extra{mode} || 0 },
691 { name => 'content-type', value => 'application/grpc',
692 mode => $extra{mode} || 1, huff => 1 },
693 { name => 'x-connection', value => $n,
694 mode => 2, huff => 1 },
695 ]}, $sid);
696 $c->h2_body('Hello world', { body_more => 1,
697 body_padding => $extra{body_padding} });
698
699 # stick trailers and subsequent frames for reproducibility
700
701 my $fld = $c->hpack('grpc-status', '0', mode => 2);
702 my $trailers = pack("x2CCCN", length($fld), 1, 5, $sid) . $fld;
703 my $window = pack("xxCCCNN", 4, 8, 0, $sid, 42);
704 my $rst = pack("x2C2xNN", 4, 3, $sid, 0);
705 my $cnl = pack("x2C2xNN", 4, 3, $sid, 8);
706
707 $trailers .= $window if $uri eq '/Discard_WU';
708 $trailers .= $rst if $uri eq '/Discard_NE';
709 $trailers .= ($rst x 3) if $uri eq '/Discard_NE3';
710 $trailers .= $cnl if $uri eq '/Discard_CNL';
711 Test::Nginx::HTTP2::raw_write($client, $trailers);
712
713 return $s->read(all => [{ fin => 1 }], wait => 2)
714 if $uri eq '/Discard_WU' || $uri eq '/Discard_NE';
715 return $s->read(all => [{ type => 'RST_STREAM' }]);
716 };
653 return $f; 717 return $f;
654 } 718 }
655 719
656 sub log2i { Test::Nginx::log_core('|| <<', @_); } 720 sub log2i { Test::Nginx::log_core('|| <<', @_); }
657 sub log2o { Test::Nginx::log_core('|| >>', @_); } 721 sub log2o { Test::Nginx::log_core('|| >>', @_); }