From 3a27d27642432d5dd4f9571d4a3e78fab740031c Mon Sep 17 00:00:00 2001 From: Vladislav Tsendrovskii Date: Fri, 16 Mar 2018 00:08:45 +0300 Subject: [PATCH] Fix handling asyncore and parsing error --- tempesta_fw/t/functional/helpers/deproxy.py | 21 +++++++++++++------ .../long_body/test_response_wrong_length.py | 2 +- .../t/functional/testers/functional.py | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tempesta_fw/t/functional/helpers/deproxy.py b/tempesta_fw/t/functional/helpers/deproxy.py index 16e26e4f8a..fe22ef6ddf 100644 --- a/tempesta_fw/t/functional/helpers/deproxy.py +++ b/tempesta_fw/t/functional/helpers/deproxy.py @@ -25,7 +25,6 @@ class ParseError(Exception): class IncompliteMessage(ParseError): pass - class HeaderCollection(object): """ A collection class for HTTP Headers. This class combines aspects of a list @@ -547,11 +546,11 @@ def handle_read(self): self.response_buffer = self.response_buffer[len(response.msg):] except IncompliteMessage: return - except ParseError as err: + except ParseError: tf_cfg.dbg(4, ('Deproxy: Client: Can\'t parse message\n' '<<<<<\n%s>>>>>' % self.response_buffer)) - raise err + raise if len(self.response_buffer) > 0: # TODO: take care about pipelined case raise ParseError('Garbage after response end:\n```\n%s\n```\n' % \ @@ -573,7 +572,10 @@ def handle_write(self): def handle_error(self): _, v, _ = sys.exc_info() - error.bug('\tDeproxy: Client: %s' % v) + if type(v) == ParseError or type(v) == AssertionError: + raise v + else: + error.bug('\tDeproxy: Client: %s' % v) @@ -685,14 +687,21 @@ def handle_accept(self): self.connections.append(handler) assert len(self.connections) <= self.conns_n, \ ('Too lot connections, expect %d, got %d' - & (self.conns_n, len(self.connections))) + % (self.conns_n, len(self.connections))) + + def handle_read_event(self): + asyncore.dispatcher.handle_read_event(self) def active_conns_n(self): return len(self.connections) def handle_error(self): _, v, _ = sys.exc_info() - raise Exception('\tDeproxy: Server %s:%d: %s' % (self.ip, self.port, v)) + if type(v) == AssertionError: + raise v + else: + raise Exception('\tDeproxy: Server %s:%d: %s' % \ + (self.ip, self.port, type(v))) def handle_close(self): self.stop() diff --git a/tempesta_fw/t/functional/long_body/test_response_wrong_length.py b/tempesta_fw/t/functional/long_body/test_response_wrong_length.py index ada8075900..49ebc17fdb 100644 --- a/tempesta_fw/t/functional/long_body/test_response_wrong_length.py +++ b/tempesta_fw/t/functional/long_body/test_response_wrong_length.py @@ -104,7 +104,7 @@ def __init__(self, *args, **kwargs): base[0].server_response.headers.add('Content-Length', "%i" % base[1]) base[0].server_response.build_message() - base[0].response = chains.response_500() + base[0].response = chains.make_502_expected() self.message_chains = [base[0]] self.cookies = [] diff --git a/tempesta_fw/t/functional/testers/functional.py b/tempesta_fw/t/functional/testers/functional.py index 1c1e408bee..7079a9f09e 100644 --- a/tempesta_fw/t/functional/testers/functional.py +++ b/tempesta_fw/t/functional/testers/functional.py @@ -150,7 +150,7 @@ def generic_test_routine(self, tempesta_defconfig, message_chains): try: self.tester.run() except ParseError as err: - self.assertTrue(False, msg=str(type(err))) + self.assertTrue(False, msg=err) self.tempesta.get_stats() self.assert_tempesta()