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
import time
+import pytest
+
import utils
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')
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