Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test where connection shuts down before response completes #468

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ add_test_case(h1_client_response_close_header_with_pipelining)
add_test_case(h1_client_respects_stream_window)
add_test_case(h1_client_connection_window_with_buffer)
add_test_case(h1_client_connection_window_with_small_buffer)
add_test_case(h1_client_request_cancelled_by_channel_shutdown)
add_test_case(h1_client_request_cancelled_by_channel_shutdown_before_response)
add_test_case(h1_client_request_cancelled_by_channel_shutdown_mid_response)
add_test_case(h1_client_multiple_requests_cancelled_by_channel_shutdown)
add_test_case(h1_client_new_request_fails_if_channel_shut_down)
add_test_case(h1_client_error_from_outgoing_body_callback_stops_decoder)
Expand Down
42 changes: 41 additions & 1 deletion tests/test_h1_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,8 @@ H1_CLIENT_TEST_CASE(h1_client_request_chunks_cancelled_by_channel_shutdown) {
return AWS_OP_SUCCESS;
}

H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown) {
/* If channel shuts down before any response is received, the request should complete with an error */
H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown_before_response) {
(void)ctx;
struct tester tester;
ASSERT_SUCCESS(s_tester_init(&tester, allocator));
Expand Down Expand Up @@ -3311,6 +3312,45 @@ H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown) {
return AWS_OP_SUCCESS;
}

/* If channel shuts down in the middle of a response, the request should complete with an error */
H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown_mid_response) {
(void)ctx;
struct tester tester;
ASSERT_SUCCESS(s_tester_init(&tester, allocator));

/* send request */
struct aws_http_message *request = s_new_default_get_request(allocator);

struct client_stream_tester stream_tester;
ASSERT_SUCCESS(s_stream_tester_init(&stream_tester, &tester, request));

testing_channel_drain_queued_tasks(&tester.testing_channel);

/* Ensure the request can be destroyed after request is sent */
aws_http_message_destroy(request);

/* send response that is 1 byte short of being complete */
const char *response_str = "HTTP/1.1 200 OK\r\n"
"Content-Length: 4\r\n"
"\r\n"
"123";
ASSERT_SUCCESS(testing_channel_push_read_str(&tester.testing_channel, response_str));

/* shutdown channel while response is 1 byte short of being complete */
aws_channel_shutdown(tester.testing_channel.channel, AWS_ERROR_SUCCESS);
testing_channel_drain_queued_tasks(&tester.testing_channel);

/* the request should complete with error, having only received a partial response */
ASSERT_TRUE(stream_tester.complete);
ASSERT_INT_EQUALS(AWS_ERROR_HTTP_CONNECTION_CLOSED, stream_tester.on_complete_error_code);
ASSERT_UINT_EQUALS(3, stream_tester.response_body.len);

/* clean up */
client_stream_tester_clean_up(&stream_tester);
ASSERT_SUCCESS(s_tester_clean_up(&tester));
return AWS_OP_SUCCESS;
}

H1_CLIENT_TEST_CASE(h1_client_multiple_requests_cancelled_by_channel_shutdown) {
(void)ctx;
struct tester tester;
Expand Down
Loading