pytests: import test_close (test4)

parent e7e5758e
......@@ -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
......
......@@ -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')
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment