From: Tomas Krizek Date: Wed, 14 Nov 2018 12:33:49 +0000 (+0100) Subject: pytests: import test_close (test4) X-Git-Tag: v3.2.0~18^2~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ffc447ae619944cb53706743403e8b4efca1425b;p=thirdparty%2Fknot-resolver.git pytests: import test_close (test4) --- diff --git a/tests/pytests/kresd.py b/tests/pytests/kresd.py index 0f9e174c6..54617b8bc 100644 --- a/tests/pytests/kresd.py +++ b/tests/pytests/kresd.py @@ -77,7 +77,7 @@ class Kresd(ContextDecorator): if self.process.returncode is not None: raise RuntimeError("Kresd crashed with returncode: {}".format( self.process.returncode)) - except RuntimeError: # pylint: disable=try-except-raise + except (RuntimeError, ConnectionError): # pylint: disable=try-except-raise raise finally: # handle cases where we accidentally attempt to bind to same port diff --git a/tests/pytests/test_conn_mgmt.py b/tests/pytests/test_conn_mgmt.py index 2f884be54..be56148aa 100644 --- a/tests/pytests/test_conn_mgmt.py +++ b/tests/pytests/test_conn_mgmt.py @@ -2,6 +2,8 @@ import time +import pytest + import utils @@ -51,3 +53,19 @@ def test_long_lived(kresd_sock): while time.time() < end_time: time.sleep(3) utils.ping_alive(kresd_sock) + + +def test_close(kresd_sock): + """ + Test establishes a TCP connection and pauses (MAX_TIMEOUT) right after establising. + Then tries to send DNS message. + + Expected: kresd closes the connection + """ + time.sleep(utils.MAX_TIMEOUT) + + with pytest.raises(BrokenPipeError, message="kresd didn't close the connection"): + try: + utils.ping_alive(kresd_sock) + except ConnectionResetError: + pytest.skip('TCP RST') diff --git a/tests/pytests/utils.py b/tests/pytests/utils.py index 55cc819c2..896840ef7 100644 --- a/tests/pytests/utils.py +++ b/tests/pytests/utils.py @@ -33,7 +33,7 @@ def receive_parse_answer(sock): data_answer = receive_answer(sock) if data_answer is None: - raise RuntimeError("Kresd closed connection") + raise BrokenPipeError("kresd closed connection") msg_answer = dns.message.from_wire(data_answer, one_rr_per_rrset=True) return msg_answer