@@ -522,9 +522,10 @@ static int s_test_s3_cancel_mpu_one_part_completed_fc(struct aws_allocator *allo
522522AWS_TEST_CASE (test_s3_cancel_mpd_one_part_completed_fc , s_test_s3_cancel_mpd_one_part_completed_fc )
523523static int s_test_s3_cancel_mpd_one_part_completed_fc (struct aws_allocator * allocator , void * ctx ) {
524524 (void )ctx ;
525+ struct aws_byte_cursor source_key = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("/pre-existing-2GB" );
525526
526- ASSERT_SUCCESS (s3_cancel_test_helper_fc (
527- allocator , S3_UPDATE_CANCEL_TYPE_MPD_ONE_PART_COMPLETED , g_pre_existing_object_10MB , AWS_SCA_CRC32 ));
527+ ASSERT_SUCCESS (
528+ s3_cancel_test_helper_fc ( allocator , S3_UPDATE_CANCEL_TYPE_MPD_ONE_PART_COMPLETED , source_key , AWS_SCA_CRC32 ));
528529
529530 return 0 ;
530531}
@@ -850,3 +851,104 @@ static int s_test_s3_cancel_prepare(struct aws_allocator *allocator, void *ctx)
850851
851852 return 0 ;
852853}
854+
855+ static void s_test_s3_cancel_schedule_prepare_meta_request_prepare_request (
856+ struct aws_s3_meta_request * meta_request ,
857+ struct aws_s3_request * request ,
858+ aws_s3_meta_request_prepare_request_callback_fn * callback ,
859+ void * user_data ) {
860+
861+ struct aws_s3_meta_request_test_results * results = meta_request -> user_data ;
862+ AWS_ASSERT (results != NULL );
863+
864+ struct aws_s3_tester * tester = results -> tester ;
865+ AWS_ASSERT (tester != NULL );
866+
867+ /* Cancel the request during schedule preparing. */
868+ struct test_s3_cancel_prepare_user_data * test_user_data = tester -> user_data ;
869+
870+ ++ test_user_data -> request_prepare_counters [request -> request_tag ];
871+
872+ /* Cancel after the second part before it prepared, so that the prepare should fail with cancelled error. */
873+ if (request -> request_tag == AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_PART &&
874+ test_user_data -> request_prepare_counters [AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_PART ] == 2 ) {
875+ aws_s3_meta_request_cancel (meta_request );
876+ }
877+
878+ struct aws_s3_meta_request_vtable * original_meta_request_vtable =
879+ aws_s3_tester_get_meta_request_vtable_patch (tester , 0 )-> original_vtable ;
880+ original_meta_request_vtable -> schedule_prepare_request (meta_request , request , callback , user_data );
881+ }
882+
883+ static struct aws_s3_meta_request * s_test_s3_cancel_schedule_prepare_meta_request_factory (
884+ struct aws_s3_client * client ,
885+ const struct aws_s3_meta_request_options * options ) {
886+ AWS_ASSERT (client != NULL );
887+
888+ struct aws_s3_tester * tester = client -> shutdown_callback_user_data ;
889+ AWS_ASSERT (tester != NULL );
890+
891+ struct aws_s3_client_vtable * original_client_vtable =
892+ aws_s3_tester_get_client_vtable_patch (tester , 0 )-> original_vtable ;
893+
894+ struct aws_s3_meta_request * meta_request = original_client_vtable -> meta_request_factory (client , options );
895+
896+ struct aws_s3_meta_request_vtable * patched_meta_request_vtable =
897+ aws_s3_tester_patch_meta_request_vtable (tester , meta_request , NULL );
898+ patched_meta_request_vtable -> schedule_prepare_request =
899+ s_test_s3_cancel_schedule_prepare_meta_request_prepare_request ;
900+
901+ return meta_request ;
902+ }
903+
904+ /* Cancel during preparing the data. */
905+ AWS_TEST_CASE (test_s3_cancel_schedule_prepare , s_test_s3_cancel_schedule_prepare )
906+ static int s_test_s3_cancel_schedule_prepare (struct aws_allocator * allocator , void * ctx ) {
907+ (void )ctx ;
908+
909+ struct aws_s3_tester tester ;
910+ ASSERT_SUCCESS (aws_s3_tester_init (allocator , & tester ));
911+
912+ struct test_s3_cancel_prepare_user_data test_user_data ;
913+ AWS_ZERO_STRUCT (test_user_data );
914+ tester .user_data = & test_user_data ;
915+
916+ struct aws_s3_client * client = NULL ;
917+
918+ struct aws_s3_tester_client_options client_options ;
919+ AWS_ZERO_STRUCT (client_options );
920+
921+ ASSERT_SUCCESS (aws_s3_tester_client_new (& tester , & client_options , & client ));
922+
923+ struct aws_s3_client_vtable * patched_client_vtable = aws_s3_tester_patch_client_vtable (& tester , client , NULL );
924+ patched_client_vtable -> meta_request_factory = s_test_s3_cancel_schedule_prepare_meta_request_factory ;
925+
926+ {
927+ struct aws_s3_tester_meta_request_options options = {
928+ .allocator = allocator ,
929+ .client = client ,
930+ .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT ,
931+ .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE ,
932+ .put_options =
933+ {
934+ .ensure_multipart = true,
935+ .file_on_disk = true,
936+ },
937+ };
938+
939+ ASSERT_SUCCESS (aws_s3_tester_send_meta_request_with_options (& tester , & options , NULL ));
940+ }
941+
942+ ASSERT_TRUE (
943+ test_user_data .request_prepare_counters [AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_CREATE_MULTIPART_UPLOAD ] == 1 );
944+ ASSERT_TRUE (test_user_data .request_prepare_counters [AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_PART ] == 2 );
945+ ASSERT_TRUE (
946+ test_user_data .request_prepare_counters [AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_ABORT_MULTIPART_UPLOAD ] == 1 );
947+ ASSERT_TRUE (
948+ test_user_data .request_prepare_counters [AWS_S3_AUTO_RANGED_PUT_REQUEST_TAG_COMPLETE_MULTIPART_UPLOAD ] == 0 );
949+
950+ aws_s3_client_release (client );
951+ aws_s3_tester_clean_up (& tester );
952+
953+ return 0 ;
954+ }
0 commit comments