Skip to content

Commit 7af5e6f

Browse files
removed OOM test, since that's no longer allowed, (#343)
* removed OOM test, since that's no longer allowed,
1 parent deab609 commit 7af5e6f

File tree

3 files changed

+2
-120
lines changed

3 files changed

+2
-120
lines changed

tests/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ add_test_case(message_request_path)
3232
add_test_case(message_response_status)
3333
add_test_case(message_refcounts)
3434
add_test_case(message_with_existing_headers)
35-
add_test_case(message_handles_oom)
3635

3736
add_test_case(h1_test_get_request)
3837
add_test_case(h1_test_request_bad_version)
@@ -218,7 +217,6 @@ add_test_case(websocket_boot_fail_before_response_headers_done)
218217
add_test_case(websocket_boot_fail_at_response_status)
219218
add_test_case(websocket_boot_fail_at_new_handler)
220219
add_test_case(websocket_boot_report_unexpected_http_shutdown)
221-
add_test_case(websocket_boot_fail_because_oom)
222220
add_test_case(websocket_handshake_key_max_length)
223221
add_test_case(websocket_handshake_key_randomness)
224222

tests/test_message.c

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <aws/common/string.h>
77
#include <aws/http/request_response.h>
88
#include <aws/http/status_code.h>
9-
#include <aws/testing/aws_test_allocators.h>
9+
#include <aws/testing/aws_test_harness.h>
1010

1111
#define TEST_CASE(NAME) \
1212
AWS_TEST_CASE(NAME, s_test_##NAME); \
@@ -368,78 +368,3 @@ TEST_CASE(message_with_existing_headers) {
368368
aws_http_message_release(message);
369369
return AWS_OP_SUCCESS;
370370
}
371-
372-
/* Do every operation that involves allocating some memory */
373-
static int s_message_handles_oom_attempt(struct aws_http_message *request) {
374-
ASSERT_NOT_NULL(request);
375-
376-
/* Set, and then overwrite, method and path */
377-
ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("POST")));
378-
ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/")));
379-
ASSERT_SUCCESS(aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("GET")));
380-
ASSERT_SUCCESS(aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/chat")));
381-
382-
/* Add a lot of headers, enough to force the underlying array-list to expand.
383-
* (just loop through the list above again and again) */
384-
char name_buf[16];
385-
char value_buf[16];
386-
for (size_t i = 0; i < 128; ++i) {
387-
snprintf(name_buf, sizeof(name_buf), "Name-%zu", i);
388-
snprintf(name_buf, sizeof(name_buf), "Value-%zu", i);
389-
struct aws_http_header header = {.name = aws_byte_cursor_from_c_str(name_buf),
390-
.value = aws_byte_cursor_from_c_str(value_buf)};
391-
ASSERT_SUCCESS(aws_http_message_add_header(request, header));
392-
}
393-
394-
/* Overwrite all the headers */
395-
for (size_t i = 0; i < 128; ++i) {
396-
snprintf(name_buf, sizeof(name_buf), "New-Name-%zu", i);
397-
snprintf(name_buf, sizeof(name_buf), "New-Value-%zu", i);
398-
struct aws_http_header header = {.name = aws_byte_cursor_from_c_str(name_buf),
399-
.value = aws_byte_cursor_from_c_str(value_buf)};
400-
ASSERT_SUCCESS(aws_http_headers_set(aws_http_message_get_headers(request), header.name, header.value));
401-
}
402-
403-
return AWS_OP_SUCCESS;
404-
}
405-
406-
TEST_CASE(message_handles_oom) {
407-
(void)ctx;
408-
struct aws_allocator timebomb_alloc;
409-
ASSERT_SUCCESS(aws_timebomb_allocator_init(&timebomb_alloc, allocator, SIZE_MAX));
410-
411-
bool test_succeeded = false;
412-
size_t allocations_until_failure;
413-
for (allocations_until_failure = 0; allocations_until_failure < 10000; ++allocations_until_failure) {
414-
/* Allow one more allocation each time we loop. */
415-
aws_timebomb_allocator_reset_countdown(&timebomb_alloc, allocations_until_failure);
416-
417-
/* Create a request, then do a bunch of stuff with it. */
418-
struct aws_http_message *request = aws_http_message_new_request(&timebomb_alloc);
419-
int err = 0;
420-
if (request) {
421-
err = s_message_handles_oom_attempt(request);
422-
if (err) {
423-
/* Ensure failure was due to OOM */
424-
ASSERT_INT_EQUALS(AWS_ERROR_OOM, aws_last_error());
425-
} else {
426-
test_succeeded = true;
427-
}
428-
429-
aws_http_message_destroy(request);
430-
} else {
431-
/* Ensure failure was due to OOM */
432-
ASSERT_INT_EQUALS(AWS_ERROR_OOM, aws_last_error());
433-
}
434-
435-
if (test_succeeded) {
436-
break;
437-
}
438-
}
439-
440-
ASSERT_TRUE(test_succeeded);
441-
ASSERT_TRUE(allocations_until_failure > 2); /* Assert that this did fail a few times */
442-
443-
aws_timebomb_allocator_clean_up(&timebomb_alloc);
444-
return AWS_OP_SUCCESS;
445-
}

tests/test_websocket_bootstrap.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <aws/http/request_response.h>
1111
#include <aws/io/logging.h>
1212
#include <aws/io/uri.h>
13-
#include <aws/testing/aws_test_allocators.h>
13+
#include <aws/testing/aws_test_harness.h>
1414

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

606-
/* Run connection process with an allocator that fakes running out of memory after N allocations. */
607-
TEST_CASE(websocket_boot_fail_because_oom) {
608-
(void)ctx;
609-
610-
struct aws_allocator timebomb_alloc;
611-
ASSERT_SUCCESS(aws_timebomb_allocator_init(&timebomb_alloc, allocator, SIZE_MAX));
612-
613-
/* Only use the timebomb allocator with actual the tester, not the logger or other systems. */
614-
s_tester.alloc = &timebomb_alloc;
615-
616-
ASSERT_SUCCESS(s_tester_init(allocator));
617-
618-
/* In a loop, keep trying to connect, allowing more and more allocations to succeed,
619-
* until the connection completes successfully */
620-
bool websocket_connect_eventually_succeeded = false;
621-
const int max_tries = 10000;
622-
int timer;
623-
for (timer = 0; timer < max_tries; ++timer) {
624-
aws_timebomb_allocator_reset_countdown(&timebomb_alloc, timer);
625-
626-
int websocket_connect_error_code;
627-
ASSERT_SUCCESS(s_drive_websocket_connect(&websocket_connect_error_code));
628-
629-
if (websocket_connect_error_code) {
630-
/* Assert that proper error code bubbled all the way out */
631-
ASSERT_TRUE(websocket_connect_error_code == AWS_ERROR_OOM);
632-
} else {
633-
/* Break out of loop once websocket_connect() succeeds. */
634-
websocket_connect_eventually_succeeded = true;
635-
break;
636-
}
637-
}
638-
639-
ASSERT_TRUE(websocket_connect_eventually_succeeded);
640-
ASSERT_TRUE(timer >= 2); /* Assert that we actually did fail a few times */
641-
642-
ASSERT_SUCCESS(s_tester_clean_up());
643-
aws_timebomb_allocator_clean_up(&timebomb_alloc);
644-
return AWS_OP_SUCCESS;
645-
}
646-
647606
/* Check that AWS_WEBSOCKET_MAX_HANDSHAKE_KEY_LENGTH is sufficiently large */
648607
TEST_CASE(websocket_handshake_key_max_length) {
649608
(void)allocator;

0 commit comments

Comments
 (0)