Merge "Cleanup nits from container_update_timeout"

This commit is contained in:
Jenkins 2015-08-06 00:27:14 +00:00 committed by Gerrit Code Review
commit 67fcc37b73
2 changed files with 44 additions and 59 deletions

View File

@ -130,7 +130,7 @@ Request timeout to external services. The default is 3 seconds.
.IP \fBconn_timeout\fR
Connection timeout to external services. The default is 0.5 seconds.
.IP \fBcontainer_update_timeout\fR
Request timeout to do a container update on an object update. The default is 1 second.
Time to wait while sending a container update on object update. The default is 1 second.
.RE
.PD

View File

@ -77,7 +77,6 @@ def fake_spawn():
ensure that the method has completed.
"""
orig = object_server.spawn
greenlets = []
def _inner_fake_spawn(func, *a, **kw):
@ -86,16 +85,12 @@ def fake_spawn():
return gt
object_server.spawn = _inner_fake_spawn
try:
yield
finally:
for gt in greenlets:
try:
with mock.patch('swift.obj.server.spawn', _inner_fake_spawn):
try:
yield
finally:
for gt in greenlets:
gt.wait()
except: # noqa
pass # real spawn won't do anything but pollute logs
object_server.spawn = orig
@patch_policies(test_policies)
@ -110,7 +105,8 @@ class TestObjectController(unittest.TestCase):
self.testdir = os.path.join(self.tmpdir,
'tmp_test_object_server_ObjectController')
mkdirs(os.path.join(self.testdir, 'sda1'))
self.conf = {'devices': self.testdir, 'mount_check': 'false'}
self.conf = {'devices': self.testdir, 'mount_check': 'false',
'container_update_timeout': 0.0}
self.object_controller = object_server.ObjectController(
self.conf, logger=debug_logger())
self.object_controller.bytes_per_sync = 1
@ -1335,10 +1331,10 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect',
mock_http_connect(201)):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(201)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time())
req = Request.blank(
@ -1351,10 +1347,10 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect',
mock_http_connect(500)):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time())
req = Request.blank(
@ -1367,10 +1363,10 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
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)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500, with_exc=True)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)
def test_PUT_ssync_multi_frag(self):
@ -2510,10 +2506,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/plain'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
@ -2550,10 +2545,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/html'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
@ -2589,10 +2583,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/enriched'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
@ -2628,10 +2621,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 204)
self.assertEquals(1, len(container_updates))
@ -2660,10 +2652,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 404)
self.assertEquals(1, len(container_updates))
@ -3130,10 +3121,9 @@ class TestObjectController(unittest.TestCase):
'X-Delete-At-Partition': '6237',
'X-Delete-At-Device': 'sdp,sdq'})
with mock.patch.object(object_server, 'http_connect',
fake_http_connect):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect', fake_http_connect):
resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201)
@ -3244,10 +3234,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
'X-Container-Device': 'sdb1, sdf1'})
with mock.patch.object(object_server, 'http_connect',
fake_http_connect):
with fake_spawn():
req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect', fake_http_connect):
req.get_response(self.object_controller)
http_connect_args.sort(key=operator.itemgetter('ipaddr'))
@ -3322,10 +3311,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 mocked_http_conn(
with fake_spawn(), mocked_http_conn(
500, 500, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(2, len(container_updates))
@ -3559,10 +3547,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Partition': 'cpartition',
'X-Container-Device': 'cdevice',
'Content-Type': 'text/plain'}, body='')
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(container_updates), 1)
@ -3601,10 +3588,9 @@ class TestObjectController(unittest.TestCase):
}
req = Request.blank('/sda1/0/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers, body='')
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(container_updates), 1)
@ -3643,9 +3629,8 @@ 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 mocked_http_conn(500) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mocked_http_conn(500) as fake_conn:
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(given_args), 7)