Skip to content
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
2 changes: 0 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ add_test_case(message_request_path)
add_test_case(message_response_status)
add_test_case(message_refcounts)
add_test_case(message_with_existing_headers)
add_test_case(message_handles_oom)

add_test_case(h1_test_get_request)
add_test_case(h1_test_request_bad_version)
Expand Down Expand Up @@ -218,7 +217,6 @@ add_test_case(websocket_boot_fail_before_response_headers_done)
add_test_case(websocket_boot_fail_at_response_status)
add_test_case(websocket_boot_fail_at_new_handler)
add_test_case(websocket_boot_report_unexpected_http_shutdown)
add_test_case(websocket_boot_fail_because_oom)
add_test_case(websocket_handshake_key_max_length)
add_test_case(websocket_handshake_key_randomness)

Expand Down
77 changes: 1 addition & 76 deletions tests/test_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <aws/common/string.h>
#include <aws/http/request_response.h>
#include <aws/http/status_code.h>
#include <aws/testing/aws_test_allocators.h>
#include <aws/testing/aws_test_harness.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could nuke the whole aws_test_allocators.h file from common

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what broke everything


#define TEST_CASE(NAME) \
AWS_TEST_CASE(NAME, s_test_##NAME); \
Expand Down Expand Up @@ -368,78 +368,3 @@ TEST_CASE(message_with_existing_headers) {
aws_http_message_release(message);
return AWS_OP_SUCCESS;
}

/* Do every operation that involves allocating some memory */
static int s_message_handles_oom_attempt(struct aws_http_message *request) {
ASSERT_NOT_NULL(request);

/* Set, and then overwrite, method and path */
ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("POST")));
ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/")));
ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("GET")));
ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/chat")));

/* Add a lot of headers, enough to force the underlying array-list to expand.
* (just loop through the list above again and again) */
char name_buf[16];
char value_buf[16];
for (size_t i = 0; i < 128; ++i) {
snprintf(name_buf, sizeof(name_buf), "Name-%zu", i);
snprintf(name_buf, sizeof(name_buf), "Value-%zu", i);
struct aws_http_header header = {.name = aws_byte_cursor_from_c_str(name_buf),
.value = aws_byte_cursor_from_c_str(value_buf)};
ASSERT_SUCCESS(aws_http_message_add_header(request, header));
}

/* Overwrite all the headers */
for (size_t i = 0; i < 128; ++i) {
snprintf(name_buf, sizeof(name_buf), "New-Name-%zu", i);
snprintf(name_buf, sizeof(name_buf), "New-Value-%zu", i);
struct aws_http_header header = {.name = aws_byte_cursor_from_c_str(name_buf),
.value = aws_byte_cursor_from_c_str(value_buf)};
ASSERT_SUCCESS(aws_http_headers_set(aws_http_message_get_headers(request), header.name, header.value));
}

return AWS_OP_SUCCESS;
}

TEST_CASE(message_handles_oom) {
(void)ctx;
struct aws_allocator timebomb_alloc;
ASSERT_SUCCESS(aws_timebomb_allocator_init(&timebomb_alloc, allocator, SIZE_MAX));

bool test_succeeded = false;
size_t allocations_until_failure;
for (allocations_until_failure = 0; allocations_until_failure < 10000; ++allocations_until_failure) {
/* Allow one more allocation each time we loop. */
aws_timebomb_allocator_reset_countdown(&timebomb_alloc, allocations_until_failure);

/* Create a request, then do a bunch of stuff with it. */
struct aws_http_message *request = aws_http_message_new_request(&timebomb_alloc);
int err = 0;
if (request) {
err = s_message_handles_oom_attempt(request);
if (err) {
/* Ensure failure was due to OOM */
ASSERT_INT_EQUALS(AWS_ERROR_OOM, aws_last_error());
} else {
test_succeeded = true;
}

aws_http_message_destroy(request);
} else {
/* Ensure failure was due to OOM */
ASSERT_INT_EQUALS(AWS_ERROR_OOM, aws_last_error());
}

if (test_succeeded) {
break;
}
}

ASSERT_TRUE(test_succeeded);
ASSERT_TRUE(allocations_until_failure > 2); /* Assert that this did fail a few times */

aws_timebomb_allocator_clean_up(&timebomb_alloc);
return AWS_OP_SUCCESS;
}
43 changes: 1 addition & 42 deletions tests/test_websocket_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <aws/http/request_response.h>
#include <aws/io/logging.h>
#include <aws/io/uri.h>
#include <aws/testing/aws_test_allocators.h>
#include <aws/testing/aws_test_harness.h>

#if _MSC_VER
# pragma warning(disable : 4204) /* non-constant aggregate initializer */
Expand Down Expand Up @@ -603,47 +603,6 @@ TEST_CASE(websocket_boot_report_unexpected_http_shutdown) {
return s_websocket_boot_fail_at_step_test(allocator, ctx, BOOT_STEP_HTTP_SHUTDOWN);
}

/* Run connection process with an allocator that fakes running out of memory after N allocations. */
TEST_CASE(websocket_boot_fail_because_oom) {
(void)ctx;

struct aws_allocator timebomb_alloc;
ASSERT_SUCCESS(aws_timebomb_allocator_init(&timebomb_alloc, allocator, SIZE_MAX));

/* Only use the timebomb allocator with actual the tester, not the logger or other systems. */
s_tester.alloc = &timebomb_alloc;

ASSERT_SUCCESS(s_tester_init(allocator));

/* In a loop, keep trying to connect, allowing more and more allocations to succeed,
* until the connection completes successfully */
bool websocket_connect_eventually_succeeded = false;
const int max_tries = 10000;
int timer;
for (timer = 0; timer < max_tries; ++timer) {
aws_timebomb_allocator_reset_countdown(&timebomb_alloc, timer);

int websocket_connect_error_code;
ASSERT_SUCCESS(s_drive_websocket_connect(&websocket_connect_error_code));

if (websocket_connect_error_code) {
/* Assert that proper error code bubbled all the way out */
ASSERT_TRUE(websocket_connect_error_code == AWS_ERROR_OOM);
} else {
/* Break out of loop once websocket_connect() succeeds. */
websocket_connect_eventually_succeeded = true;
break;
}
}

ASSERT_TRUE(websocket_connect_eventually_succeeded);
ASSERT_TRUE(timer >= 2); /* Assert that we actually did fail a few times */

ASSERT_SUCCESS(s_tester_clean_up());
aws_timebomb_allocator_clean_up(&timebomb_alloc);
return AWS_OP_SUCCESS;
}

/* Check that AWS_WEBSOCKET_MAX_HANDSHAKE_KEY_LENGTH is sufficiently large */
TEST_CASE(websocket_handshake_key_max_length) {
(void)allocator;
Expand Down