From 1f4370f8383a25ca9766a30a26679a93fea8c84e Mon Sep 17 00:00:00 2001 From: Alex Rogozhnikov Date: Tue, 24 Sep 2024 10:23:34 -0700 Subject: [PATCH] add a test with prime pad sizes to exclude cases of divisibility by block_size, min_upload_size --- s3fs/tests/test_s3fs.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/s3fs/tests/test_s3fs.py b/s3fs/tests/test_s3fs.py index 2a2df2cf..2275519a 100644 --- a/s3fs/tests/test_s3fs.py +++ b/s3fs/tests/test_s3fs.py @@ -2781,3 +2781,21 @@ def test_upload_parts(s3_fixed_upload_size): with s3_fixed_upload_size.open(a, "r") as f: assert len(f.read()) == 6_001_000 * 2 + + +def test_upload_part_with_prime_pads(s3_fixed_upload_size): + block = 6_000_000 + pad1, pad2 = 1013, 1019 # prime pad sizes to exclude divisibility + with s3_fixed_upload_size.open(a, "wb", block_size=block) as f: + f.write(b" " * (block + pad1)) + assert len(f.buffer.getbuffer()) == pad1 + # check we are at the right position + assert f.tell() == block + pad1 + assert f.offset == block + f.write(b" " * (block + pad2)) + assert len(f.buffer.getbuffer()) == pad1 + pad2 + assert f.tell() == 2 * block + pad1 + pad2 + assert f.offset == 2 * block + + with s3_fixed_upload_size.open(a, "r") as f: + assert len(f.read()) == 2 * block + pad1 + pad2