comparison grpc.t @ 1624:81fd6615358e

Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 24 Nov 2020 16:11:13 +0000
parents 3fe652bc9dae
children 62a1667f60f8
comparison
equal deleted inserted replaced
1623:3fe652bc9dae 1624:81fd6615358e
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(111); 27 ->has(qw/upstream_keepalive/)->plan(113);
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
511 511
512 $f->{http_start}('/Discard_CNL'); 512 $f->{http_start}('/Discard_CNL');
513 $frames = $f->{discard}(); 513 $frames = $f->{discard}();
514 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; 514 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
515 is($frame->{flags}, undef, 'discard CANCEL - no trailers'); 515 is($frame->{flags}, undef, 'discard CANCEL - no trailers');
516
517 # upstream keepalive, grpc error
518 # receiving END_STREAM followed by RST_STREAM NO_ERROR
519
520 $f->{http_start}('/KeepAlive');
521 $f->{data}('Hello');
522 $frames = $f->{http_err_rst}();
523 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
524 ok($frame->{headers}{'grpc-status'}, 'keepalive 3 - grpc error, rst');
525
526 $frames = $f->{http_start}('/KeepAlive', reuse => 1);
527 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
528
529 TODO: {
530 local $TODO = 'not yet' unless $t->has_version('1.19.5');
531
532 ok($frame, 'keepalive 3 - connection reused');
533
534 }
535
536 undef $f;
537 $f = grpc();
516 538
517 ############################################################################### 539 ###############################################################################
518 540
519 sub grpc { 541 sub grpc {
520 my ($server, $client, $f, $s, $c, $sid, $csid, $uri); 542 my ($server, $client, $f, $s, $c, $sid, $csid, $uri);
658 mode => 2, huff => 1 }, 680 mode => 2, huff => 1 },
659 ]}, $sid); 681 ]}, $sid);
660 682
661 return $s->read(all => [{ fin => 1 }]); 683 return $s->read(all => [{ fin => 1 }]);
662 }; 684 };
685 $f->{http_err_rst} = sub {
686 $c->start_chain();
687 $c->new_stream({ headers => [
688 { name => ':status', value => '200', mode => 0 },
689 { name => 'content-type', value => 'application/grpc' },
690 { name => 'grpc-status', value => '12', mode => 2 },
691 { name => 'grpc-message', value => 'unknown service',
692 mode => 2 },
693 ]}, $sid);
694 $c->h2_rst($sid, 0);
695 $c->send_chain();
696
697 return $s->read(all => [{ fin => 1 }]);
698 };
663 $f->{http_err2} = sub { 699 $f->{http_err2} = sub {
664 my %extra = @_; 700 my %extra = @_;
665 $c->new_stream({ body_more => 1, headers => [ 701 $c->new_stream({ body_more => 1, headers => [
666 { name => ':status', value => '200', mode => 0 }, 702 { name => ':status', value => '200', mode => 0 },
667 { name => 'content-type', value => 'application/grpc', 703 { name => 'content-type', value => 'application/grpc',