Tests: udploop's silence counted from the last answer

The last datagram's time was taken after the sleep following it, half a
second and a slow runner's overshoot late, so a session ending on time
looked early. The test resolver no longer raises when its socket is
closed under it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-23 13:56:38 +03:00
parent e619a105b4
commit 83d8138818

View File

@ -81,7 +81,11 @@ def fake_name_server(answer, tcp=False, wrongid=False):
reply = dns_reply(data, answer) reply = dns_reply(data, answer)
if wrongid: if wrongid:
reply = bytes([reply[0] ^ 0x55, reply[1]]) + reply[2:] reply = bytes([reply[0] ^ 0x55, reply[1]]) + reply[2:]
try:
sock.sendto(reply, peer) sock.sendto(reply, peer)
except OSError:
# closed once the case is done with it
return
if tcp: if tcp:
sock.listen(8) sock.listen(8)
@ -177,11 +181,13 @@ def run(t):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
answered = 0 answered = 0
for i in range(10): for i in range(10):
if i:
time.sleep(0.5)
if exchange(s, idle, f"k{i}".encode()) == f"echo:k{i}".encode(): if exchange(s, idle, f"k{i}".encode()) == f"echo:k{i}".encode():
answered += 1 answered += 1
time.sleep(0.5) # the silence counts from the last answer, not a sleep after it
cport = s.getsockname()[1]
last = time.time() last = time.time()
cport = s.getsockname()[1]
t.eq(10, answered, "a datagram every half second for five seconds is answered") t.eq(10, answered, "a datagram every half second for five seconds is answered")
t.ok("and the session lives on through them") if not idle_ended() else \ t.ok("and the session lives on through them") if not idle_ended() else \
t.fail("and the session lives on through them", "no 00092 line", "ended") t.fail("and the session lives on through them", "no 00092 line", "ended")