From 1841bd6010e91859a4fe97afa4da980b8daa1e03 Mon Sep 17 00:00:00 2001 From: Alistair Coles <alistair.coles@hp.com> Date: Tue, 8 Sep 2015 10:22:32 +0100 Subject: [PATCH] Initialise delete_object mock before it is called Attempt to fix the linked bug by initialising the mock instance for Connection.delete_object before calling the SwiftService upload method, so that the delete_object mock already exists before the delete_segments jobs that run in multiple threads call it. Otherwise there is a risk that the delete_segment job threads could race while creating either the delete_object mock or the delete_object.return_value mock, resulting in each thread getting a different instance. That would explain the intermittent test failures reported in the bug. Change-Id: Ia82697c093529076b0bbcc6bccd577afdf0839e1 Partial-Bug: #1480223 --- tests/unit/test_shell.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index e2b87d0f..66bf3284 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -538,6 +538,9 @@ class TestShell(unittest.TestCase): b' {"name": "container2/old_seg2"}]' ) connection.return_value.put_object.return_value = EMPTY_ETAG + # create the delete_object child mock here in attempt to fix + # https://bugs.launchpad.net/python-swiftclient/+bug/1480223 + connection.return_value.delete_object.return_value = None swiftclient.shell.main(argv) connection.return_value.put_object.assert_called_with( 'container', @@ -604,9 +607,11 @@ class TestShell(unittest.TestCase): 'last_modified': '123T456'}]], [None, []] ] - connection.return_value.put_object.return_value = ( - 'd41d8cd98f00b204e9800998ecf8427e') + connection.return_value.put_object.return_value = EMPTY_ETAG swiftclient.shell.main(argv) + # create the delete_object child mock here in attempt to fix + # https://bugs.launchpad.net/python-swiftclient/+bug/1480223 + connection.return_value.delete_object.return_value = None connection.return_value.put_object.assert_called_with( 'container', self.tmpfile.lstrip('/'),