Repository: tikv/tikv
File: components/cloud/aws/src/s3.rs (Rust)

Code before:
        assert_eq!(
            CLOUD_REQUEST_HISTOGRAM_VEC
                .get_metric_with_label_values(&["s3", "upload_part"])
                .unwrap()
                .get_sample_count(),
            // length of magic_contents
            (magic_contents.len() / multi_part_size) as u64,
        );
    }

    #[tokio::test]
    async fn test_s3_storage_multi_part_abort() {
        let magic_contents = "567890";

        let bucket_name = StringNonEmpty::required("mybucket".to_string()).unwrap();
        let mut bucket = BucketConf::default(bucket_name);
        bucket.region = Some(StringNonEmpty::required("cn-north-1".to_string()).unwrap());

        let mut config = Config::default(bucket);
        let multi_part_size = 2;
        // set multi_part_size to use upload_part function
        config.multi_part_size = multi_part_size;
        config.force_path_style = true;

        // split magic_contents into 3 parts, so we mock 5 requests here(1 begin + 3
        // part + 1 complete)
        let client = StaticReplayClient::new(vec![
            ReplayEvent::new(
                http::Request::builder()
                    .header("content-length", "0")
                    .uri(Uri::from_static(
                        "https://s3.cn-north-1.amazonaws.com.cn/mybucket/mykey?uploads"
                    ))
                    .body(SdkBody::from(""))
                    .unwrap(),
                http::Response::builder()
                    .status(200)
                    .body(SdkBody::from(
                        r#"<?xml version="1.0" encoding="UTF-8"?>
                            <InitiateMultipartUploadResult>
                                <Bucket>mybucket</Bucket>
                                <Key>mykey</Key>
                                <UploadId>1</UploadId>
                            </InitiateMultipartUploadResult>"#
                    )).unwrap()
            ),
            ReplayEvent::new(
                http::Request::builder()
                    .header("content-length", "2")
                    .uri(Uri::from_static(
                        "https://s3.cn-north-1.amazonaws.com.cn/mybucket/mykey?x-id=UploadPart&partNumber=1&uploadId=1"

Review comment (suggestion):
The comment above the abort test says the mocked requests are "1 complete" but the last request is actually `AbortMultipartUpload`. Updating the comment will avoid confusion when maintaining these tests.
```suggestion
        // part + 1 abort)
```

Code after:
        let sample_count_after = CLOUD_REQUEST_HISTOGRAM_VEC
            .get_metric_with_label_values(&["s3", "upload_part"])
            .unwrap()
            .get_sample_count();
        assert_eq!(
            sample_count_after - sample_count_before,
            // length of magic_contents
            (magic_contents.len() / multi_part_size) as u64,
        );
    }

    #[tokio::test]
    async fn test_s3_storage_multi_part_abort() {
        let magic_contents = "567890";

        let bucket_name = StringNonEmpty::required("mybucket".to_string()).unwrap();
        let mut bucket = BucketConf::default(bucket_name);
        bucket.region = Some(StringNonEmpty::required("cn-north-1".to_string()).unwrap());

        let mut config = Config::default(bucket);
        let multi_part_size = 2;
        // set multi_part_size to use upload_part function
        config.multi_part_size = multi_part_size;
        config.force_path_style = true;

        // Record sample count before the test to compute delta, avoiding
        // interference from other tests sharing the global metric.
        let sample_count_before = CLOUD_REQUEST_HISTOGRAM_VEC
            .get_metric_with_label_values(&["s3", "upload_part"])
            .unwrap()
            .get_sample_count();

        // split magic_contents into 3 parts, so we mock 5 requests here(1 begin + 3
        // part + 1 abort)
        let client = StaticReplayClient::new(vec![
            ReplayEvent::new(
                http::Request::builder()
                    .header("content-length", "0")
                    .uri(Uri::from_static(
                        "https://s3.cn-north-1.amazonaws.com.cn/mybucket/mykey?uploads"
                    ))
                    .body(SdkBody::from(""))
                    .unwrap(),
                http::Response::builder()
                    .status(200)
                    .body(SdkBody::from(
                        r#"<?xml version="1.0" encoding="UTF-8"?>
                            <InitiateMultipartUploadResult>
                                <Bucket>mybucket</Bucket>
                                <Key>mykey</Key>
                                <UploadId>1</UploadId>