From b823e1602e4c5cb6bcf5360b3e1f6e8410e46401 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Wed, 2 Jul 2014 11:37:26 -0700 Subject: [PATCH] Fix exception raising in FakeConn Timeout isn't an Exception, so Timeouts in tests weren't getting raised. Instead, you'd sometimes have an HTTPResponse's .status be a Timeout object, not an integer, which greatly confuses code that expects an integer. Also reorder the test that exposed the failure in the gate so it blows up most times instead of sometimes do demonstrate the failure with out this fix to FakeConn. Change-Id: I76367a0575f84cad6b2f03e814f3f16bf96bc7d1 --- test/unit/__init__.py | 8 ++++---- test/unit/proxy/test_server.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/unit/__init__.py b/test/unit/__init__.py index a508106017..058f7c8f5b 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -606,7 +606,7 @@ def fake_http_connect(*code_iter, **kwargs): def __init__(self, status, etag=None, body='', timestamp='1', headers=None): # connect exception - if isinstance(status, Exception): + if isinstance(status, (Exception, Timeout)): raise status if isinstance(status, tuple): self.expect_status, self.status = status @@ -641,11 +641,11 @@ def fake_http_connect(*code_iter, **kwargs): self._next_sleep = None def getresponse(self): - if isinstance(self.status, Exception): + if isinstance(self.status, (Exception, Timeout)): raise self.status exc = kwargs.get('raise_exc') if exc: - if isinstance(exc, Exception): + if isinstance(exc, (Exception, Timeout)): raise exc raise Exception('test') if kwargs.get('raise_timeout_exc'): @@ -653,7 +653,7 @@ def fake_http_connect(*code_iter, **kwargs): return self def getexpect(self): - if isinstance(self.expect_status, Exception): + if isinstance(self.expect_status, (Exception, Timeout)): raise self.expect_status return FakeConn(self.expect_status) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 5353b54164..1a91e1cde8 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -1601,17 +1601,17 @@ class TestObjectController(unittest.TestCase): self.assertEquals(res.status[:len(expected)], expected) test_status_map((200, 200, 201, 201, -1), 201) # connect exc # connect errors - test_status_map((200, 200, 201, 201, Timeout()), 201) + test_status_map((200, 200, Timeout(), 201, 201, ), 201) test_status_map((200, 200, 201, 201, Exception()), 201) # expect errors - test_status_map((200, 200, 201, 201, (Timeout(), None)), 201) - test_status_map((200, 200, 201, 201, (Exception(), None)), 201) + test_status_map((200, 200, (Timeout(), None), 201, 201), 201) + test_status_map((200, 200, (Exception(), None), 201, 201), 201) # response errors - test_status_map((200, 200, 201, 201, (100, Timeout())), 201) - test_status_map((200, 200, 201, 201, (100, Exception())), 201) - test_status_map((200, 200, 201, 201, 507), 201) # error limited - test_status_map((200, 200, 201, -1, -1), 503) - test_status_map((200, 200, 503, 503, -1), 503) + test_status_map((200, 200, (100, Timeout()), 201, 201), 201) + test_status_map((200, 200, (100, Exception()), 201, 201), 201) + test_status_map((200, 200, 507, 201, 201), 201) # error limited + test_status_map((200, 200, -1, 201, -1), 503) + test_status_map((200, 200, 503, -1, 503), 503) def test_PUT_send_exceptions(self): with save_globals():