]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests: import test_close (test4)
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 14 Nov 2018 12:33:49 +0000 (13:33 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 16:13:42 +0000 (17:13 +0100)
tests/pytests/kresd.py
tests/pytests/test_conn_mgmt.py
tests/pytests/utils.py

index 0f9e174c655a7f0052d5d438b707ff71f325bf74..54617b8bce362151185717fe8eacfd3a603e610a 100644 (file)
@@ -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
index 2f884be5495fe9cf16361b613b251488b48961f0..be56148aa6b1d9602f931b05bcdb708e47ddffb4 100644 (file)
@@ -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')
index 55cc819c2dcbd1ee888b863edfdee968012de568..896840ef72d92ffb8bdd9b847f012e2b157b53b0 100644 (file)
@@ -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