Wait on greenthreads before unmocking http_connect

The fake_spawn() context manager wraps spawn and waits
for greenthreads to complete (such as the async_update threads).
The wait needs to be done before http_connect is un-mocked, so
the fake_spawn context manager should exit *before* any context
manager that mocks the http_connect method.

Also add fake_spawn to _test_PUT_then_POST_async_pendings()

Related-Bug: #1536376
Related-Bug: #1514111
Closes-Bug: #1555739

Change-Id: I15f36e191cfe3ee6c82b4be56e8618ec0230e328
This commit is contained in:
Alistair Coles
2016-03-10 18:02:44 +00:00
parent 902cb8f8d7
commit 0bc5a69d41

View File

@@ -729,8 +729,9 @@ class TestObjectController(unittest.TestCase):
environ={'REQUEST_METHOD': 'PUT'},
headers=put_headers, body='test')
with mock.patch('swift.obj.server.http_connect', fake_http_connect):
with mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''):
with mock.patch('swift.obj.server.http_connect', fake_http_connect), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''), \
fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
@@ -772,8 +773,9 @@ class TestObjectController(unittest.TestCase):
environ={'REQUEST_METHOD': 'POST'},
headers=post_headers)
with mock.patch('swift.obj.server.http_connect', fake_http_connect):
with mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''):
with mock.patch('swift.obj.server.http_connect', fake_http_connect), \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', ''), \
fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 202)
@@ -836,10 +838,10 @@ class TestObjectController(unittest.TestCase):
os.listdir(os.path.join(
device_dir, diskfile.get_async_dir(policy))))
def test_PUT_then_POST_async_updates_with_repl_policy(self):
def test_PUT_then_POST_async_pendings_with_repl_policy(self):
self._test_PUT_then_POST_async_pendings(POLICIES[0])
def test_PUT_then_POST_async_updates_with_EC_policy(self):
def test_PUT_then_POST_async_pendings_with_EC_policy(self):
self._test_PUT_then_POST_async_pendings(
POLICIES[1], update_etag='override_etag')
@@ -1964,9 +1966,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(201)):
with mock.patch.object(
object_server, 'http_connect', mock_http_connect(201)):
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
timestamp = normalize_timestamp(time())
@@ -1980,9 +1982,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500)):
with mock.patch.object(
object_server, 'http_connect', mock_http_connect(500)):
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
timestamp = normalize_timestamp(time())
@@ -1996,9 +1998,10 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with fake_spawn(), mock.patch.object(
with mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500, with_exc=True)):
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
@@ -3198,8 +3201,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/plain'})
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -3237,8 +3240,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/html'})
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -3275,8 +3278,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/enriched'})
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -3313,8 +3316,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 204)
@@ -3344,8 +3347,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 404)
@@ -3813,8 +3816,9 @@ class TestObjectController(unittest.TestCase):
'X-Delete-At-Partition': '6237',
'X-Delete-At-Device': 'sdp,sdq'})
with fake_spawn(), mock.patch.object(
with mock.patch.object(
object_server, 'http_connect', fake_http_connect):
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
@@ -3925,8 +3929,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
'X-Container-Device': 'sdb1, sdf1'})
with fake_spawn(), mock.patch.object(
with mock.patch.object(
object_server, 'http_connect', fake_http_connect):
with fake_spawn():
req.get_response(self.object_controller)
http_connect_args.sort(key=operator.itemgetter('ipaddr'))
@@ -4002,8 +4007,9 @@ class TestObjectController(unittest.TestCase):
headers['X-Object-Sysmeta-Ec-Frag-Index'] = '2'
req = Request.blank(
'/sda1/p/a/c/o', method='PUT', body='', headers=headers)
with fake_spawn(), mocked_http_conn(
with mocked_http_conn(
500, 500, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -4238,8 +4244,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Partition': 'cpartition',
'X-Container-Device': 'cdevice',
'Content-Type': 'text/plain'}, body='')
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -4279,8 +4285,8 @@ class TestObjectController(unittest.TestCase):
}
req = Request.blank('/sda1/0/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers, body='')
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with mocked_http_conn(200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
@@ -4320,7 +4326,7 @@ class TestObjectController(unittest.TestCase):
given_args[:] = args
diskfile_mgr = self.object_controller._diskfile_router[policy]
diskfile_mgr.pickle_async_update = fake_pickle_async_update
with fake_spawn(), mocked_http_conn(500) as fake_conn:
with mocked_http_conn(500) as fake_conn, fake_spawn():
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)