From 00297df63b5c2d660dafa5314b3c87a57cfaf0b8 Mon Sep 17 00:00:00 2001 From: ctiller <ctiller@google.com> Date: Mon, 12 Jan 2015 11:23:09 -0800 Subject: Ensure flow control callbacks happen outside the transport lock. Split encoding into two phases: a collection phase to decide on what is allowed (by flow control) to be sent, and a framing phase when the data is actually sent. Perform the second phase outside of the transport mutex (but serially, guarded by t->writing) and make flow control callbacks during that phase. This will allow us to make further transport level calls in response to flow control callbacks, and will be needed by the forthcoming async api for C++. Change on 2015/01/12 by ctiller <ctiller@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=83774409 --- test/core/transport/chttp2/stream_encoder_test.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'test/core/transport') diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index 3ee11d94e8..ba552786db 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -64,15 +64,20 @@ static gpr_slice create_test_slice(size_t length) { static void verify_sopb(size_t window_available, int eof, size_t expect_window_used, const char *expected) { gpr_slice_buffer output; + grpc_stream_op_buffer encops; gpr_slice merged; gpr_slice expect = parse_hexstring(expected); gpr_slice_buffer_init(&output); + grpc_sopb_init(&encops); GPR_ASSERT(expect_window_used == - grpc_chttp2_encode_some(g_sopb.ops, &g_sopb.nops, eof, &output, - window_available, 0xdeadbeef, - &g_compressor)); + grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available, + &encops)); + grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor, + &output); + encops.nops = 0; merged = grpc_slice_merge(output.slices, output.count); gpr_slice_buffer_destroy(&output); + grpc_sopb_destroy(&encops); if (0 != gpr_slice_cmp(merged, expect)) { char *expect_str = @@ -240,21 +245,25 @@ static void test_decode_random_headers_inner(int max_len) { test_decode_random_header_state st; gpr_slice_buffer output; gpr_slice merged; + grpc_stream_op_buffer encops; grpc_chttp2_hpack_parser parser; grpc_chttp2_hpack_parser_init(&parser, g_mdctx); + grpc_sopb_init(&encops); gpr_log(GPR_INFO, "max_len = %d", max_len); - for (i = 0; i < 100000; i++) { + for (i = 0; i < 10000; i++) { randstr(st.key, max_len); randstr(st.value, max_len); add_sopb_header(st.key, st.value); gpr_slice_buffer_init(&output); - GPR_ASSERT(0 == grpc_chttp2_encode_some(g_sopb.ops, &g_sopb.nops, 0, - &output, 0, 0xdeadbeef, - &g_compressor)); + GPR_ASSERT(0 == + grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, 0, &encops)); + grpc_chttp2_encode(encops.ops, encops.nops, 0, 0xdeadbeef, &g_compressor, + &output); + encops.nops = 0; merged = grpc_slice_merge(output.slices, output.count); gpr_slice_buffer_destroy(&output); @@ -269,6 +278,7 @@ static void test_decode_random_headers_inner(int max_len) { } grpc_chttp2_hpack_parser_destroy(&parser); + grpc_sopb_destroy(&encops); } #define DECL_TEST_DECODE_RANDOM_HEADERS(n) \ -- cgit v1.2.3