config.addinivalue_line(
"markers", "dnspython2: mark tests that need dnspython >= 2.0.0"
)
+ config.addinivalue_line(
+ "markers", "long: mark tests that take a long time to run"
+ )
def pytest_collection_modifyitems(config, items):
if "dnspython2" in item.keywords:
item.add_marker(skip_dnspython2)
+ skip_long_tests = pytest.mark.skip(
+ reason="need CI_ENABLE_ALL_TESTS environment variable")
+ if not os.environ.get("CI_ENABLE_ALL_TESTS"):
+ for item in items:
+ if "long" in item.keywords:
+ item.add_marker(skip_long_tests)
+
@pytest.fixture
def port(request):
(response, rtime) = dns.query.receive_tcp(sock, timeout())
except ConnectionError as e:
raise EOFError from e
+
+
+@pytest.mark.dnspython
+@pytest.mark.dnspython2
+@pytest.mark.long
+def test_max_transfer_idle_out(port):
+ import dns.query
+ import dns.rdataclass
+ import dns.rdatatype
+
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ sock.connect(("10.53.0.1", port))
+
+ name = dns.name.from_text("example.")
+ msg = create_msg("example.", "AXFR")
+ (sbytes, stime) = dns.query.send_tcp(sock, msg, timeout())
+
+ # Receive the initial DNS message with SOA
+ (response, rtime) = dns.query.receive_tcp(sock, timeout(),
+ one_rr_per_rrset=True)
+ soa = response.get_rrset(dns.message.ANSWER, name,
+ dns.rdataclass.IN, dns.rdatatype.SOA)
+ assert soa is not None
+
+ time.sleep(61) # max-transfer-idle-out is 1 minute
+
+ with pytest.raises(ConnectionResetError):
+ # Process queued TCP messages
+ while True:
+ (response, rtime) = \
+ dns.query.receive_tcp(sock, timeout(),
+ one_rr_per_rrset=True)
+ soa = response.get_rrset(dns.message.ANSWER, name,
+ dns.rdataclass.IN, dns.rdatatype.SOA)
+ if soa is not None:
+ break
+ assert soa is None
+
+
+@pytest.mark.dnspython
+@pytest.mark.dnspython2
+@pytest.mark.long
+def test_max_transfer_time_out(port):
+ import dns.query
+ import dns.rdataclass
+ import dns.rdatatype
+
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ sock.connect(("10.53.0.1", port))
+
+ name = dns.name.from_text("example.")
+ msg = create_msg("example.", "AXFR")
+ (sbytes, stime) = dns.query.send_tcp(sock, msg, timeout())
+
+ # Receive the initial DNS message with SOA
+ (response, rtime) = dns.query.receive_tcp(sock, timeout(),
+ one_rr_per_rrset=True)
+ soa = response.get_rrset(dns.message.ANSWER, name,
+ dns.rdataclass.IN, dns.rdatatype.SOA)
+ assert soa is not None
+
+ # The loop should timeout at the 5 minutes (max-transfer-time-out)
+ with pytest.raises(EOFError):
+ while True:
+ time.sleep(1)
+ (response, rtime) = \
+ dns.query.receive_tcp(sock, timeout(),
+ one_rr_per_rrset=True)
+ soa = response.get_rrset(dns.message.ANSWER, name,
+ dns.rdataclass.IN, dns.rdatatype.SOA)
+ if soa is not None:
+ break
+ assert soa is None