def METHOD_NAME(self, attempts: int = 30) -> None:
    """
    Polls the DNS server over TCP until it gets a response, or until
    it runs out of attempts and raises a ValueError.
    The DNS response message must match the txn_id of the DNS query message,
    but otherwise the contents are ignored.
    :param int attempts: The number of attempts to make.
    """
    if not self.process:
        raise ValueError("DNS server has not been started. Please run start() first.")
    for _ in range(attempts):
        if self.process.poll():
            raise ValueError("BIND9 server stopped unexpectedly")
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(5.0)
        try:
            sock.connect(BIND_BIND_ADDRESS)
            sock.sendall(BIND_TEST_QUERY)
            buf = sock.recv(1024)
            # We should receive a DNS message with the same tx_id
            if buf and len(buf) > 4 and buf[2:4] == BIND_TEST_QUERY[2:4]:
                return
            # If we got a response but it wasn't the one we wanted, wait a little
            time.sleep(1)
        except:  # pylint: disable=bare-except
            # If there was a network error, wait a little
            time.sleep(1)
        finally:
            sock.close()
    raise ValueError(
        "Gave up waiting for DNS server {} to respond".format(BIND_BIND_ADDRESS)
    )