Skip to content

Commit 0e350e3

Browse files
add failing acquire test
1 parent 68b7212 commit 0e350e3

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

source/s3_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ void s_acquire_mem_and_prepare_request(
19091909
}
19101910
/* END CRITICAL SECTION */
19111911

1912-
/* Note: run callback async on event loop. this is done to avoid any race conditions between cancelling
1912+
/* Note: run callback async on event loop. this is done to avoid any deadlocks between cancelling
19131913
which requires a lock on meta request and buffer acquire callback which also requires a lock. */
19141914
aws_future_s3_buffer_ticket_register_event_loop_callback(
19151915
payload->buffer_future, meta_request->io_event_loop, s_on_pool_buffer_reserved, payload);

source/s3_default_buffer_pool.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ void s_default_pool_trim(struct aws_s3_buffer_pool *pool) {
189189

190190
static struct aws_s3_buffer_pool_vtable s_default_pool_vtable = {
191191
.reserve = s_default_pool_reserve,
192-
.trim = s_default_pool_trim};
192+
.trim = s_default_pool_trim,
193+
};
193194

194195
struct aws_s3_buffer_pool *aws_s3_default_buffer_pool_new(
195196
struct aws_allocator *allocator,

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ add_test_case(test_s3_buffer_pool_trim)
394394
add_test_case(test_s3_buffer_pool_reserve_over_limit)
395395
add_test_case(test_s3_buffer_pool_too_small)
396396
add_net_test_case(test_s3_put_object_buffer_pool_trim)
397+
add_net_test_case(test_s3_put_object_buffer_acquire_error)
397398
add_test_case(test_s3_buffer_pool_forced_buffer)
398399
add_test_case(test_s3_buffer_pool_forced_buffer_after_limit_hit)
399400
add_test_case(test_s3_buffer_pool_forced_buffer_wont_stop_reservations)

tests/s3_data_plane_tests.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,79 @@ static int s_test_s3_put_object_sse_c_aes256_multipart_with_checksum(struct aws_
33503350
return 0;
33513351
}
33523352

3353+
struct aws_future_s3_buffer_ticket *s_failing_pool_reserve(
3354+
struct aws_s3_buffer_pool *pool,
3355+
struct aws_s3_buffer_pool_reserve_meta meta) {
3356+
3357+
struct aws_future_s3_buffer_ticket *future = aws_future_s3_buffer_ticket_new((struct aws_allocator *)pool->impl);
3358+
aws_future_s3_buffer_ticket_set_error(future, AWS_ERROR_S3_BUFFER_ALLOCATION_FAILED);
3359+
return future;
3360+
}
3361+
3362+
static struct aws_s3_buffer_pool_vtable s_failing_pool_vtable = {
3363+
.reserve = s_failing_pool_reserve,
3364+
.trim = NULL,
3365+
};
3366+
3367+
struct aws_s3_buffer_pool *s_always_error_buffer_pool_fn(struct aws_allocator *allocator,
3368+
struct aws_s3_buffer_pool_config config) {
3369+
struct aws_s3_buffer_pool *pool = aws_mem_calloc(allocator, 1, sizeof(struct aws_s3_buffer_pool));
3370+
pool->impl = allocator;
3371+
pool->vtable = &s_failing_pool_vtable;
3372+
aws_ref_count_init(&pool->ref_count, pool, (aws_simple_completion_callback *)aws_s3_default_buffer_pool_destroy);
3373+
}
3374+
3375+
AWS_TEST_CASE(
3376+
test_s3_put_object_buffer_acquire_error,
3377+
s_test_s3_put_object_buffer_acquire_error)
3378+
static int test_s3_put_object_buffer_acquire_error(struct aws_allocator *allocator, void *ctx) {
3379+
(void)ctx;
3380+
3381+
struct aws_s3_tester tester;
3382+
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
3383+
3384+
struct aws_s3_client_config client_config = {
3385+
.part_size = 8 * 1024 * 1024,
3386+
.buffer_pool_factory_fn = s_always_error_buffer_pool_fn
3387+
};
3388+
3389+
ASSERT_SUCCESS(aws_s3_tester_bind_client(
3390+
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING));
3391+
3392+
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);
3393+
3394+
ASSERT_TRUE(client != NULL);
3395+
3396+
struct aws_byte_buf path_buf;
3397+
AWS_ZERO_STRUCT(path_buf);
3398+
3399+
ASSERT_SUCCESS(aws_s3_tester_upload_file_path_init(
3400+
tester.allocator, &path_buf, aws_byte_cursor_from_c_str("/prefix/round_trip/test_sse_c_fc.txt")));
3401+
3402+
struct aws_byte_cursor object_path = aws_byte_cursor_from_buf(&path_buf);
3403+
3404+
struct aws_s3_tester_meta_request_options put_options = {
3405+
.allocator = allocator,
3406+
.meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
3407+
.client = client,
3408+
.sse_type = AWS_S3_TESTER_SSE_C_AES256,
3409+
.checksum_algorithm = AWS_SCA_CRC32,
3410+
.put_options =
3411+
{
3412+
.object_size_mb = 10,
3413+
.object_path_override = object_path,
3414+
},
3415+
};
3416+
3417+
ASSERT_INT_EQUALS(AWS_ERROR_S3_BUFFER_ALLOCATION_FAILED, aws_s3_tester_send_meta_request_with_options(&tester, &put_options, NULL));
3418+
client = aws_s3_client_release(client);
3419+
3420+
aws_byte_buf_clean_up(&path_buf);
3421+
aws_s3_tester_clean_up(&tester);
3422+
3423+
return 0;
3424+
}
3425+
33533426
static int s_test_s3_put_object_content_md5_helper(
33543427
struct aws_allocator *allocator,
33553428
bool multipart_upload,

0 commit comments

Comments
 (0)