From 29962c20347b324650760f021a6e81f25925893e Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Tue, 15 Feb 2022 16:50:49 -0800 Subject: [PATCH 1/7] h2 stream callback not kill connection --- source/h2_stream.c | 7 +- tests/CMakeLists.txt | 3 + tests/test_h2_client.c | 239 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+), 4 deletions(-) diff --git a/source/h2_stream.c b/source/h2_stream.c index 0e7728bd2..7d3a1864f 100644 --- a/source/h2_stream.c +++ b/source/h2_stream.c @@ -761,10 +761,9 @@ struct aws_h2err aws_h2_stream_on_decoder_headers_i( if (stream->base.on_incoming_headers) { if (stream->base.on_incoming_headers(&stream->base, block_type, header, 1, stream->base.user_data)) { - /* #TODO: callback errors should be Stream Errors, not Connection Errors */ AWS_H2_STREAM_LOGF( ERROR, stream, "Incoming header callback raised error, %s", aws_error_name(aws_last_error())); - return aws_h2err_from_last_error(); + return s_send_rst_and_close_stream(stream, aws_h2err_from_last_error()); } } @@ -811,7 +810,7 @@ struct aws_h2err aws_h2_stream_on_decoder_headers_end( stream, "Incoming-header-block-done callback raised error, %s", aws_error_name(aws_last_error())); - return aws_h2err_from_last_error(); + return s_send_rst_and_close_stream(stream, aws_h2err_from_last_error()); } } @@ -931,7 +930,7 @@ struct aws_h2err aws_h2_stream_on_decoder_data_i(struct aws_h2_stream *stream, s if (stream->base.on_incoming_body(&stream->base, &data, stream->base.user_data)) { AWS_H2_STREAM_LOGF( ERROR, stream, "Incoming body callback raised error, %s", aws_error_name(aws_last_error())); - return aws_h2err_from_last_error(); + return s_send_rst_and_close_stream(stream, aws_h2err_from_last_error()); } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f8ceb8fe3..ad2b43945 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -445,6 +445,9 @@ add_test_case(h2_client_get_received_goaway) add_test_case(h2_client_request_apis_failed_after_connection_begin_shutdown) add_test_case(h2_client_get_local_settings) add_test_case(h2_client_get_remote_settings) +add_test_case(h2_client_error_from_incoming_headers_callback_reset_stream) +add_test_case(h2_client_error_from_incoming_headers_done_callback_reset_stream) +add_test_case(h2_client_error_from_incoming_body_callback_reset_stream) add_test_case(server_new_destroy) add_test_case(connection_setup_shutdown) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index c5030bf02..4c32aba9f 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4859,3 +4859,242 @@ TEST_CASE(h2_client_request_apis_failed_after_connection_begin_shutdown) { aws_http_stream_release(stream); return s_tester_clean_up(); } + +/* TODO: test outgoing body after the input stream refcount */ +enum request_callback { + // REQUEST_CALLBACK_OUTGOING_BODY, + REQUEST_CALLBACK_INCOMING_HEADERS, + REQUEST_CALLBACK_INCOMING_HEADERS_DONE, + REQUEST_CALLBACK_INCOMING_BODY, + REQUEST_CALLBACK_COMPLETE, + REQUEST_CALLBACK_COUNT, +}; + +struct error_from_callback_tester { + enum request_callback error_at; + int callback_counts[REQUEST_CALLBACK_COUNT]; + bool has_errored; + struct aws_stream_status status; + int on_complete_error_code; +}; + +static const int ERROR_FROM_CALLBACK_ERROR_CODE = (int)0xBEEFCAFE; + +static int s_error_from_callback_common( + struct error_from_callback_tester *error_tester, + enum request_callback current_callback) { + + error_tester->callback_counts[current_callback]++; + + /* After error code returned, no more callbacks should fire (except for on_complete) */ + AWS_FATAL_ASSERT(!error_tester->has_errored); + AWS_FATAL_ASSERT(current_callback <= error_tester->error_at); + if (current_callback == error_tester->error_at) { + error_tester->has_errored = true; + return aws_raise_error(ERROR_FROM_CALLBACK_ERROR_CODE); + } + + return AWS_OP_SUCCESS; +} + +// static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct aws_byte_buf *dest) { + +// (void)dest; + +// struct error_from_callback_tester *error_tester = body->impl; +// if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { +// return AWS_OP_ERR; +// } + +// /* If the common fn was successful, write out some data and end the stream */ +// ASSERT_TRUE(aws_byte_buf_write(dest, (const uint8_t *)"abcd", 4)); +// error_tester->status.is_end_of_stream = true; +// return AWS_OP_SUCCESS; +// } + +// static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) { +// struct error_from_callback_tester *error_tester = body->impl; +// *status = error_tester->status; +// return AWS_OP_SUCCESS; +// } + +// static void s_error_from_outgoing_body_destroy(struct aws_input_stream *stream) { +// aws_mem_release(stream->allocator, stream); +// } + +// static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { +// .seek = NULL, +// .read = s_error_from_outgoing_body_read, +// .get_status = s_error_from_outgoing_body_get_status, +// .get_length = NULL, +// .destroy = s_error_from_outgoing_body_destroy, +// }; + +static int s_error_from_incoming_headers( + struct aws_http_stream *stream, + enum aws_http_header_block header_block, + const struct aws_http_header *header_array, + size_t num_headers, + void *user_data) { + + (void)stream; + (void)header_block; + (void)header_array; + (void)num_headers; + return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS); +} + +static int s_error_from_incoming_headers_done( + struct aws_http_stream *stream, + enum aws_http_header_block header_block, + void *user_data) { + (void)stream; + (void)header_block; + return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS_DONE); +} + +static int s_error_from_incoming_body( + struct aws_http_stream *stream, + const struct aws_byte_cursor *data, + void *user_data) { + + (void)stream; + (void)data; + return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_BODY); +} + +static void s_error_tester_on_stream_complete(struct aws_http_stream *stream, int error_code, void *user_data) { + (void)stream; + struct error_from_callback_tester *error_tester = user_data; + error_tester->callback_counts[REQUEST_CALLBACK_COMPLETE]++; + error_tester->on_complete_error_code = error_code; +} + +static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx, enum request_callback error_at) { + + ASSERT_SUCCESS(s_tester_init(allocator, ctx)); + /* get connection preface and acks out of the way */ + ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer)); + ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer)); + /* send request */ + struct aws_http_message *request = aws_http2_message_new_request(allocator); + ASSERT_NOT_NULL(request); + + struct aws_http_header request_headers_src[] = { + DEFINE_HEADER(":method", "GET"), + DEFINE_HEADER(":scheme", "https"), + DEFINE_HEADER(":path", "/"), + }; + aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src)); + + struct error_from_callback_tester error_tester = { + .error_at = error_at, + .status = + { + .is_valid = true, + .is_end_of_stream = false, + }, + }; + // struct aws_input_stream error_from_outgoing_body_stream = { + // .allocator = allocator, + // .impl = &error_tester, + // .vtable = &s_error_from_outgoing_body_vtable, + // }; + + // aws_http_message_set_body_stream(request, &error_from_outgoing_body_stream); + + struct aws_http_make_request_options opt = { + .self_size = sizeof(opt), + .request = request, + .on_response_headers = s_error_from_incoming_headers, + .on_response_header_block_done = s_error_from_incoming_headers_done, + .on_response_body = s_error_from_incoming_body, + .on_complete = s_error_tester_on_stream_complete, + .user_data = &error_tester, + }; + testing_channel_drain_queued_tasks(&s_tester.testing_channel); + + struct aws_http_stream *stream = aws_http_connection_make_request(s_tester.connection, &opt); + ASSERT_NOT_NULL(stream); + ASSERT_SUCCESS(aws_http_stream_activate(stream)); + + testing_channel_drain_queued_tasks(&s_tester.testing_channel); + + /* Ensure the request can be destroyed after request is sent */ + aws_http_message_release(opt.request); + + /* fake peer sends response headers */ + struct aws_http_header response_headers_src[] = { + DEFINE_HEADER(":status", "200"), + DEFINE_HEADER("date", "Fri, 01 Mar 2019 17:18:55 GMT"), + }; + + struct aws_http_headers *response_headers = aws_http_headers_new(allocator); + aws_http_headers_add_array(response_headers, response_headers_src, AWS_ARRAY_SIZE(response_headers_src)); + uint32_t stream_id = aws_http_stream_get_id(stream); + struct aws_h2_frame *response_frame = + aws_h2_frame_new_headers(allocator, stream_id, response_headers, false /*end_stream*/, 0, NULL); + ASSERT_SUCCESS(h2_fake_peer_send_frame(&s_tester.peer, response_frame)); + + struct aws_byte_buf response_body_bufs; + size_t body_length = 5; + + /* fake peer sends a DATA frame larger than the window size we have */ + ASSERT_SUCCESS(aws_byte_buf_init(&response_body_bufs, allocator, body_length)); + ASSERT_TRUE(aws_byte_buf_write_u8_n(&response_body_bufs, (uint8_t)'a', body_length)); + struct aws_byte_cursor body_cursor = aws_byte_cursor_from_buf(&response_body_bufs); + ASSERT_SUCCESS(h2_fake_peer_send_data_frame(&s_tester.peer, stream_id, body_cursor, true /*end_stream*/)); + + /* validate that stream completed with error */ + testing_channel_drain_queued_tasks(&s_tester.testing_channel); + + /* check that callbacks were invoked before error_at, but not after */ + for (int i = 0; i < REQUEST_CALLBACK_COMPLETE; ++i) { + if (i <= error_at) { + ASSERT_TRUE(error_tester.callback_counts[i] > 0); + } else { + ASSERT_INT_EQUALS(0, error_tester.callback_counts[i]); + } + } + + /* validate the RST_STREAM sent and connection is still open */ + ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer)); + struct h2_decoded_frame *rst_stream_frame = + h2_decode_tester_find_frame(&s_tester.peer.decode, AWS_H2_FRAME_T_RST_STREAM, 0, NULL); + ASSERT_NOT_NULL(rst_stream_frame); + ASSERT_UINT_EQUALS(AWS_HTTP2_ERR_INTERNAL_ERROR, rst_stream_frame->error_code); + ASSERT_TRUE(aws_http_connection_is_open(s_tester.connection)); + + /* the on_complete callback should always fire though, and should receive the proper error_code */ + ASSERT_INT_EQUALS(1, error_tester.callback_counts[REQUEST_CALLBACK_COMPLETE]); + ASSERT_INT_EQUALS(ERROR_FROM_CALLBACK_ERROR_CODE, error_tester.on_complete_error_code); + + aws_http_headers_release(response_headers); + aws_byte_buf_clean_up(&response_body_bufs); + aws_http_stream_release(stream); + return s_tester_clean_up(); +} + +// TEST_CASE(h2_client_error_from_outgoing_body_callback_reset_stream) { +// (void)ctx; +// ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_OUTGOING_BODY)); +// return AWS_OP_SUCCESS; +// } + +TEST_CASE(h2_client_error_from_incoming_headers_callback_reset_stream) { + (void)ctx; + ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_HEADERS)); + return AWS_OP_SUCCESS; +} + +TEST_CASE(h2_client_error_from_incoming_headers_done_callback_reset_stream) { + (void)ctx; + ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_HEADERS_DONE)); + return AWS_OP_SUCCESS; +} + +TEST_CASE(h2_client_error_from_incoming_body_callback_reset_stream) { + (void)ctx; + ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_BODY)); + return AWS_OP_SUCCESS; +} From fcb6b2b6bea593501966afdc5a07011736017ad6 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Thu, 3 Mar 2022 14:01:19 -0800 Subject: [PATCH 2/7] change log to be less frequent --- source/http2_stream_manager.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/source/http2_stream_manager.c b/source/http2_stream_manager.c index 7d89887db..283675cf5 100644 --- a/source/http2_stream_manager.c +++ b/source/http2_stream_manager.c @@ -98,7 +98,6 @@ static void s_sm_count_increase_synced( for (size_t i = 0; i < num; i++) { aws_ref_count_acquire(&stream_manager->internal_ref_count); } - s_sm_log_stats_synced(stream_manager); } static void s_sm_count_decrease_synced( @@ -109,15 +108,12 @@ static void s_sm_count_decrease_synced( for (size_t i = 0; i < num; i++) { aws_ref_count_release(&stream_manager->internal_ref_count); } - s_sm_log_stats_synced(stream_manager); } static void s_aws_stream_management_transaction_init( struct aws_http2_stream_management_transaction *work, struct aws_http2_stream_manager *stream_manager) { AWS_ZERO_STRUCT(*work); - - STREAM_MANAGER_LOGF(TRACE, stream_manager, "work:%p inits", (void *)work); aws_linked_list_init(&work->pending_make_requests); work->stream_manager = stream_manager; work->allocator = stream_manager->allocator; @@ -126,7 +122,6 @@ static void s_aws_stream_management_transaction_init( static void s_aws_stream_management_transaction_clean_up(struct aws_http2_stream_management_transaction *work) { (void)work; - STREAM_MANAGER_LOGF(TRACE, work->stream_manager, "work:%p clean up", (void *)work); AWS_ASSERT(aws_linked_list_empty(&work->pending_make_requests)); aws_ref_count_release(&work->stream_manager->internal_ref_count); } @@ -390,6 +385,7 @@ static void s_aws_http2_stream_manager_build_transaction_synced(struct aws_http2 stream_manager->synced_data.finish_pending_stream_acquisitions_task_scheduled = true; } } + s_sm_log_stats_synced(stream_manager); } static struct aws_h2_sm_connection *s_sm_connection_new( @@ -453,7 +449,7 @@ static void s_sm_on_connection_acquired(struct aws_http_connection *connection, s_sm_count_decrease_synced(stream_manager, AWS_SMCT_CONNECTIONS_ACQUIRING, 1); if (error_code || !connection) { STREAM_MANAGER_LOGF( - WARN, + ERROR, stream_manager, "connection acquired from connection manager failed, with error: %d(%s)", error_code, @@ -621,7 +617,6 @@ static void s_sm_connection_on_scheduled_stream_finishes( aws_random_access_set_remove(&stream_manager->synced_data.ideal_available_set, sm_connection); work.sm_connection_to_release = sm_connection; --stream_manager->synced_data.holding_connections_count; - s_sm_log_stats_synced(stream_manager); } s_unlock_synced_data(stream_manager); } /* END CRITICAL SECTION */ @@ -745,7 +740,6 @@ static void s_make_request_task(struct aws_channel_task *task, void *arg, enum a static void s_aws_http2_stream_manager_execute_transaction(struct aws_http2_stream_management_transaction *work) { struct aws_http2_stream_manager *stream_manager = work->stream_manager; - STREAM_MANAGER_LOGF(TRACE, stream_manager, "work:%p executes", (void *)work); /* Step1: Release connection */ if (work->sm_connection_to_release) { From 2949fd22ca23d74ae402e6bee1d9f0e1d0b50221 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 9 May 2022 10:28:04 -0700 Subject: [PATCH 3/7] add outgoing body test --- tests/CMakeLists.txt | 1 + tests/test_h2_client.c | 79 +++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6d554d999..d05eb17ed 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -453,6 +453,7 @@ add_test_case(h2_client_get_received_goaway) add_test_case(h2_client_request_apis_failed_after_connection_begin_shutdown) add_test_case(h2_client_get_local_settings) add_test_case(h2_client_get_remote_settings) +add_test_case(h2_client_error_from_outgoing_body_callback_reset_stream) add_test_case(h2_client_error_from_incoming_headers_callback_reset_stream) add_test_case(h2_client_error_from_incoming_headers_done_callback_reset_stream) add_test_case(h2_client_error_from_incoming_body_callback_reset_stream) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index cfa4cfe9c..337599538 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4878,9 +4878,8 @@ TEST_CASE(h2_client_request_apis_failed_after_connection_begin_shutdown) { return s_tester_clean_up(); } -/* TODO: test outgoing body after the input stream refcount */ enum request_callback { - // REQUEST_CALLBACK_OUTGOING_BODY, + REQUEST_CALLBACK_OUTGOING_BODY, REQUEST_CALLBACK_INCOMING_HEADERS, REQUEST_CALLBACK_INCOMING_HEADERS_DONE, REQUEST_CALLBACK_INCOMING_BODY, @@ -4889,6 +4888,7 @@ enum request_callback { }; struct error_from_callback_tester { + struct aws_input_stream base; enum request_callback error_at; int callback_counts[REQUEST_CALLBACK_COUNT]; bool has_errored; @@ -4915,38 +4915,37 @@ static int s_error_from_callback_common( return AWS_OP_SUCCESS; } -// static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct aws_byte_buf *dest) { +static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct aws_byte_buf *dest) { -// (void)dest; + (void)dest; -// struct error_from_callback_tester *error_tester = body->impl; -// if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { -// return AWS_OP_ERR; -// } - -// /* If the common fn was successful, write out some data and end the stream */ -// ASSERT_TRUE(aws_byte_buf_write(dest, (const uint8_t *)"abcd", 4)); -// error_tester->status.is_end_of_stream = true; -// return AWS_OP_SUCCESS; -// } + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); + if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { + return AWS_OP_ERR; + } -// static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) { -// struct error_from_callback_tester *error_tester = body->impl; -// *status = error_tester->status; -// return AWS_OP_SUCCESS; -// } + /* If the common fn was successful, write out some data and end the stream */ + ASSERT_TRUE(aws_byte_buf_write(dest, (const uint8_t *)"abcd", 4)); + error_tester->status.is_end_of_stream = true; + return AWS_OP_SUCCESS; +} -// static void s_error_from_outgoing_body_destroy(struct aws_input_stream *stream) { -// aws_mem_release(stream->allocator, stream); -// } +static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) { + struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); + *status = error_tester->status; + return AWS_OP_SUCCESS; +} -// static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { -// .seek = NULL, -// .read = s_error_from_outgoing_body_read, -// .get_status = s_error_from_outgoing_body_get_status, -// .get_length = NULL, -// .destroy = s_error_from_outgoing_body_destroy, -// }; +static void s_error_from_outgoing_body_destroy(void *stream) { + /* allocated from stack, nothing to do */ + (void)stream; +} +static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = { + .seek = NULL, + .read = s_error_from_outgoing_body_read, + .get_status = s_error_from_outgoing_body_get_status, + .get_length = NULL, +}; static int s_error_from_incoming_headers( struct aws_http_stream *stream, @@ -5005,7 +5004,10 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx }; aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src)); + struct aws_input_stream error_from_outgoing_body_stream; + AWS_ZERO_STRUCT(error_from_outgoing_body_stream); struct error_from_callback_tester error_tester = { + .base = error_from_outgoing_body_stream, .error_at = error_at, .status = { @@ -5013,13 +5015,10 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx .is_end_of_stream = false, }, }; - // struct aws_input_stream error_from_outgoing_body_stream = { - // .allocator = allocator, - // .impl = &error_tester, - // .vtable = &s_error_from_outgoing_body_vtable, - // }; + error_from_outgoing_body_stream.vtable = &s_error_from_outgoing_body_vtable; + aws_ref_count_init(&error_from_outgoing_body_stream.ref_count, &error_tester, s_error_from_outgoing_body_destroy); - // aws_http_message_set_body_stream(request, &error_from_outgoing_body_stream); + aws_http_message_set_body_stream(request, &error_from_outgoing_body_stream); struct aws_http_make_request_options opt = { .self_size = sizeof(opt), @@ -5093,11 +5092,11 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx return s_tester_clean_up(); } -// TEST_CASE(h2_client_error_from_outgoing_body_callback_reset_stream) { -// (void)ctx; -// ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_OUTGOING_BODY)); -// return AWS_OP_SUCCESS; -// } +TEST_CASE(h2_client_error_from_outgoing_body_callback_reset_stream) { + (void)ctx; + ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_OUTGOING_BODY)); + return AWS_OP_SUCCESS; +} TEST_CASE(h2_client_error_from_incoming_headers_callback_reset_stream) { (void)ctx; From 290340649849aad0208b05d0691b2c9541779c31 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 9 May 2022 11:26:58 -0700 Subject: [PATCH 4/7] fix the bug --- tests/test_h2_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index 337599538..6652daf0b 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4920,7 +4920,7 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct (void)dest; struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); - if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { + if (s_error_from_callback_common(error_tester, error_tester->error_at)) { return AWS_OP_ERR; } From b34fa2c9a9f9647cc8e4a544c44f6142b6c6414e Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 9 May 2022 11:32:52 -0700 Subject: [PATCH 5/7] uh --- tests/test_h2_client.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index 6652daf0b..e4ee714df 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4902,7 +4902,7 @@ static int s_error_from_callback_common( struct error_from_callback_tester *error_tester, enum request_callback current_callback) { - error_tester->callback_counts[current_callback]++; + error_tester->callback_counts[0]++; /* After error code returned, no more callbacks should fire (except for on_complete) */ AWS_FATAL_ASSERT(!error_tester->has_errored); @@ -5004,10 +5004,7 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx }; aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src)); - struct aws_input_stream error_from_outgoing_body_stream; - AWS_ZERO_STRUCT(error_from_outgoing_body_stream); struct error_from_callback_tester error_tester = { - .base = error_from_outgoing_body_stream, .error_at = error_at, .status = { @@ -5015,10 +5012,10 @@ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx .is_end_of_stream = false, }, }; - error_from_outgoing_body_stream.vtable = &s_error_from_outgoing_body_vtable; - aws_ref_count_init(&error_from_outgoing_body_stream.ref_count, &error_tester, s_error_from_outgoing_body_destroy); + error_tester.base.vtable = &s_error_from_outgoing_body_vtable; + aws_ref_count_init(&error_tester.base.ref_count, &error_tester, s_error_from_outgoing_body_destroy); - aws_http_message_set_body_stream(request, &error_from_outgoing_body_stream); + aws_http_message_set_body_stream(request, &error_tester.base); struct aws_http_make_request_options opt = { .self_size = sizeof(opt), From 892c84c997ca52a79efb37e46cbb183954c2694c Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 9 May 2022 11:33:10 -0700 Subject: [PATCH 6/7] no --- tests/test_h2_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index e4ee714df..297e72b5e 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4902,7 +4902,7 @@ static int s_error_from_callback_common( struct error_from_callback_tester *error_tester, enum request_callback current_callback) { - error_tester->callback_counts[0]++; + error_tester->callback_counts[current_callback]++; /* After error code returned, no more callbacks should fire (except for on_complete) */ AWS_FATAL_ASSERT(!error_tester->has_errored); From e1609fadde2804a338a6bfdbdbc0c24721e0a6c8 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 9 May 2022 11:37:06 -0700 Subject: [PATCH 7/7] another stupid bug --- tests/test_h2_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index 297e72b5e..0b625236d 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4920,7 +4920,7 @@ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct (void)dest; struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base); - if (s_error_from_callback_common(error_tester, error_tester->error_at)) { + if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) { return AWS_OP_ERR; }