changeset 1725:f4c79ee52d8f

Tests: added grpcs tests with flow control (ticket #2229). The tests fail with level-triggered event methods, fixed in 058a67435e83.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 23 Aug 2021 11:31:21 +0300
parents 1522ab9d37b4
children f66266cc82c8
files grpc_ssl.t
diffstat 1 files changed, 47 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/grpc_ssl.t
+++ b/grpc_ssl.t
@@ -29,7 +29,7 @@ my $t = Test::Nginx->new()->has(qw/http 
 $t->{_configure_args} =~ /OpenSSL ([\d\.]+)/;
 plan(skip_all => 'OpenSSL too old') unless defined $1 and $1 ge '1.0.2';
 
-$t->write_file_expand('nginx.conf', <<'EOF')->plan(33);
+$t->write_file_expand('nginx.conf', <<'EOF')->plan(38);
 
 %%TEST_GLOBALS%%
 
@@ -56,6 +56,8 @@ http {
         ssl_verify_client optional;
         ssl_client_certificate client.crt;
 
+        http2_body_preread_size 128k;
+
         location / {
             grpc_pass 127.0.0.1:8082;
             add_header X-Connection $connection;
@@ -66,6 +68,8 @@ http {
         listen       127.0.0.1:8080 http2;
         server_name  localhost;
 
+        http2_body_preread_size 128k;
+
         location / {
             grpc_pass grpcs://127.0.0.1:8081;
             grpc_ssl_name localhost;
@@ -189,6 +193,37 @@ is($frame->{headers}{'grpc-status'}, '0'
 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection');
 
+# flow control
+
+$f->{http_start}('/FlowControl');
+$frames = $f->{data_len}(('Hello' x 13000) . ('x' x 550), 65535);
+my $sum = eval join '+', map { $_->{type} eq "DATA" && $_->{length} } @$frames;
+is($sum, 65535, 'flow control - iws length');
+
+TODO: {
+local $TODO = 'not yet' if ($^O eq 'MSWin32' or $^O eq 'solaris')
+	and !$t->has_version('1.21.2');
+
+$f->{update}(10);
+$f->{update_sid}(10);
+
+$frames = $f->{data_len}(undef, 10);
+($frame) = grep { $_->{type} eq "DATA" } @$frames;
+is($frame->{length}, 10, 'flow control - update length');
+is($frame->{flags}, 0, 'flow control - update flags');
+
+$f->{update_sid}(10);
+$f->{update}(10);
+
+$frames = $f->{data_len}(undef, 5);
+($frame) = grep { $_->{type} eq "DATA" } @$frames;
+is($frame->{length}, 5, 'flow control - rest length');
+is($frame->{flags}, 1, 'flow control - rest flags');
+
+}
+
+$f->{http_end}();
+
 # upstream keepalive
 
 $f->{http_start}('/KeepAlive');
@@ -263,6 +298,17 @@ sub grpc {
 		$sid = $frame->{sid};
 		return $frames;
 	};
+	$f->{data_len} = sub {
+		my ($body, $len) = @_;
+		$s->h2_body($body) if defined $body;
+		return $c->read(all => [{ sid => $sid, length => $len }]);
+	};
+	$f->{update} = sub {
+		$c->h2_window(shift);
+	};
+	$f->{update_sid} = sub {
+		$c->h2_window(shift, $sid);
+	};
 	$f->{data} = sub {
 		my ($body, %extra) = @_;
 		$s->h2_body($body, { %extra });