Skip to content

Commit

Permalink
[#130] Fixed comparison to make sure multipart_global_state is cleane…
Browse files Browse the repository at this point in the history
…d up

Added test case
  • Loading branch information
JustinKyleJames committed Nov 11, 2024
1 parent 549543a commit 4c3378d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion endpoints/s3/src/abortmultipartupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void irods::s3::actions::handle_abortmultipartupload(
}

// delete the entry in the replica_token_number_and_odstream_map
if (part_shmem::replica_token_number_and_odstream_map.find(upload_id) ==
if (part_shmem::replica_token_number_and_odstream_map.find(upload_id) !=
part_shmem::replica_token_number_and_odstream_map.end())
{
// Read all of the shared pointers in the tuple to make sure they are destructed in
Expand Down
58 changes: 58 additions & 0 deletions tests/abortmultipartupload_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from unittest import *
import inspect
import os
import json
from libs.execute import *
from libs.command import *
from libs.utility import *
from host_port import s3_api_host_port, irods_host

class AbortMultipartUpload_Test(TestCase):
bucket_irods_path = '/tempZone/home/alice/alice-bucket'
bucket_name = 'alice-bucket'
s3_api_url = f'http://{s3_api_host_port}'

def __init__(self, *args, **kwargs):
super(AbortMultipartUpload_Test, self).__init__(*args, **kwargs)

def setUp(self):
pass
def tearDown(self):
pass

def test_abort_multipart_closes_stream_to_data_object__issue_130(self):
put_filename = inspect.currentframe().f_code.co_name
part_filename = f'{put_filename}.part'
try:
make_arbitrary_file(part_filename, 100*1024)

# create the multipart upload and grab the upload ID from the json response
_, out, _ = assert_command(f'aws --profile s3_api_alice --endpoint-url {self.s3_api_url} '
f's3api create-multipart-upload --bucket {self.bucket_name} --key {put_filename}',
'STDOUT_MULTILINE',
['UploadId'])
upload_id = json.loads(out)["UploadId"]

# upload two parts
assert_command(f'aws --profile s3_api_alice --endpoint-url {self.s3_api_url} '
f's3api upload-part --upload-id {upload_id} --bucket {self.bucket_name} --key {put_filename} --part-number 1 --body ./{part_filename}',
'STDOUT_SINGLELINE',
'ETag')
assert_command(f'aws --profile s3_api_alice --endpoint-url {self.s3_api_url} '
f's3api upload-part --upload-id {upload_id} --bucket {self.bucket_name} --key {put_filename} --part-number 2 --body ./{part_filename}',
'STDOUT_SINGLELINE',
'ETag')

# abort the multipart upload
assert_command(f'aws --profile s3_api_alice --endpoint-url {self.s3_api_url} '
f's3api abort-multipart-upload --bucket {self.bucket_name} --key {put_filename} --upload-id {upload_id}')

# Put the object. Without the fix for 130 this would fail as the stream remains open
assert_command(f'aws --profile s3_api_alice --endpoint-url {self.s3_api_url} '
f's3 cp {part_filename} s3://{self.bucket_name}/{put_filename}',
'STDOUT_SINGLELINE',
f'upload: ./{part_filename} to s3://{self.bucket_name}/{put_filename}')

finally:
os.remove(part_filename)
assert_command(f'irm -f {self.bucket_irods_path}/{put_filename}')
8 changes: 5 additions & 3 deletions tests/run_all_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import getobject_test
import getobject_test
import copyobject_test
import deleteobject_test
import getobject_test
Expand All @@ -8,6 +8,7 @@
import listbuckets_test
import listobject_test
import putobject_test
import abortmultipartupload_test


def run_some_tests():
Expand All @@ -21,15 +22,16 @@ def run_some_tests():
headobject_test.HeadObject_Test,
listbuckets_test.ListBuckets_Test,
listobject_test.ListObject_Test,
putobject_test.PutObject_Test]
putobject_test.PutObject_Test,
abortmultipartupload_test.AbortMultipartUpload_Test]

loader = unittest.TestLoader()

suites_list = []
for test_class in test_classes_to_run:
suite = loader.loadTestsFromTestCase(test_class)
suites_list.append(suite)

big_suite = unittest.TestSuite(suites_list)

runner = unittest.TextTestRunner()
Expand Down

0 comments on commit 4c3378d

Please sign in to comment.