Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #834 #835

Merged
merged 2 commits into from
Jul 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions awscli/customizations/s3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ def wait_for_parts_to_finish(self):

def wait_for_upload_id(self):
with self._upload_id_condition:
while self._upload_id is None:
if self._state == self._CANCELLED:
raise UploadCancelledError("Upload has been cancelled.")
self._upload_id_condition.wait(timeout=1)
while self._upload_id is None and self._state != self._CANCELLED:
self._upload_id_condition.wait(timeout=1)
if self._state == self._CANCELLED:
raise UploadCancelledError("Upload has been cancelled.")
return self._upload_id

def wait_for_completion(self):
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/customizations/s3/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ def test_can_cancel_tasks(self):
with self.assertRaises(UploadCancelledError):
self.context.wait_for_parts_to_finish()

def test_cancel_after_upload_id(self):
# We want have a thread waiting for the upload id.
upload_part_thread = threading.Thread(target=self.upload_part,
args=(1,))
self.start_thread(upload_part_thread)

# We announce the upload id.
self.create_upload('my_upload_id')
# The upload_part thread can now proceed,
# now, let's cancel this upload.
self.context.cancel_upload()

# The upload_part_thread should be finished.
self.join_threads()

# In a cancelled multipart upload task any subsequent
# call to wait_for_upload_id must raise an UploadCancelledError
with self.assertRaises(UploadCancelledError):
self.context.wait_for_upload_id()

def test_cancel_threads_waiting_for_completion(self):
# So we have a thread waiting for the entire upload to complete.
arbitrary_waiting_thread = threading.Thread(target=self.wait_for_upload_complete)
Expand Down