From 13e4e57f7e340e68cd8775cdd385a3a02a7e7bf8 Mon Sep 17 00:00:00 2001 From: Robert Minsk Date: Mon, 7 Nov 2022 18:44:40 -0800 Subject: [PATCH] Integration tests for TransferManager.shutdown() --- s3transfer/manager.py | 2 +- tests/integration/test_manager.py | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/integration/test_manager.py diff --git a/s3transfer/manager.py b/s3transfer/manager.py index b11daeba..0b7e73e5 100644 --- a/s3transfer/manager.py +++ b/s3transfer/manager.py @@ -618,7 +618,7 @@ def shutdown(self, cancel=False, cancel_msg=''): :param cancel_msg: The message to specify if canceling all in-progress transfers. """ - self._shutdown(cancel, cancel, cancel_msg) + self._shutdown(cancel, cancel_msg) def _shutdown(self, cancel, cancel_msg, exc_type=CancelledError): if cancel: diff --git a/tests/integration/test_manager.py b/tests/integration/test_manager.py new file mode 100644 index 00000000..b0d021e0 --- /dev/null +++ b/tests/integration/test_manager.py @@ -0,0 +1,33 @@ +# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +from unittest import TestCase, mock + +from s3transfer.exceptions import CancelledError +from s3transfer.futures import TransferCoordinator +from s3transfer.manager import TransferManager + + +class TestTransferManager(TestCase): + def test_shutdown_cancels_transfer_coordinator(self): + client = mock.Mock() + + cancel_msg = 'Test message' + + transfer_manager = TransferManager(client) + transfer_coordinator = TransferCoordinator() + coordinator_controller = transfer_manager.coordinator_controller + coordinator_controller.add_transfer_coordinator(transfer_coordinator) + transfer_manager.shutdown(True, cancel_msg) + + self.assertIsInstance(transfer_coordinator.exception, CancelledError) + self.assertEqual(str(transfer_coordinator.exception), cancel_msg)