Merge "Added test for timeout regression"
This commit is contained in:
commit
df11f59348
@ -457,6 +457,8 @@ def fake_http_connect(*code_iter, **kwargs):
|
||||
body_iter = iter(body_iter)
|
||||
|
||||
def connect(*args, **ckwargs):
|
||||
if kwargs.get('slow_connect', False):
|
||||
sleep(0.1)
|
||||
if 'give_content_type' in kwargs:
|
||||
if len(args) >= 7 and 'Content-Type' in args[6]:
|
||||
kwargs['give_content_type'](args[6]['Content-Type'])
|
||||
|
@ -15,9 +15,26 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
|
||||
import swift
|
||||
from swift.proxy import server as proxy_server
|
||||
from test.unit import FakeRing, FakeMemcache
|
||||
from test.unit import FakeRing, FakeMemcache, fake_http_connect
|
||||
|
||||
@contextmanager
|
||||
def set_http_connect(*args, **kwargs):
|
||||
old_connect = swift.proxy.controllers.base.http_connect
|
||||
new_connect = fake_http_connect(*args, **kwargs)
|
||||
swift.proxy.controllers.base.http_connect = new_connect
|
||||
swift.proxy.controllers.obj.http_connect = new_connect
|
||||
swift.proxy.controllers.account.http_connect = new_connect
|
||||
swift.proxy.controllers.container.http_connect = new_connect
|
||||
yield new_connect
|
||||
swift.proxy.controllers.base.http_connect = old_connect
|
||||
swift.proxy.controllers.obj.http_connect = old_connect
|
||||
swift.proxy.controllers.account.http_connect = old_connect
|
||||
swift.proxy.controllers.container.http_connect = old_connect
|
||||
|
||||
|
||||
|
||||
class TestObjControllerWriteAffinity(unittest.TestCase):
|
||||
@ -59,6 +76,13 @@ class TestObjControllerWriteAffinity(unittest.TestCase):
|
||||
# we don't skip any nodes
|
||||
self.assertEqual(sorted(all_nodes), sorted(local_first_nodes))
|
||||
|
||||
def test_connect_put_node_timeout(self):
|
||||
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
|
||||
self.app.conn_timeout = 0.1
|
||||
with set_http_connect(200, slow_connect=True):
|
||||
nodes = [dict(ip='', port='', device=''),]
|
||||
res = controller._connect_put_node(nodes, '', '', {}, ('',''))
|
||||
self.assertTrue(res is None)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user