Skip to content

Commit 5b06936

Browse files
committed
Fix unstable test
1 parent 4b4958a commit 5b06936

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

tests/test_tcp.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,24 +2470,49 @@ def test_remote_shutdown_receives_trailing_data(self):
24702470
future = None
24712471

24722472
def server(sock):
2473-
sock.starttls(sslctx, server_side=True)
2474-
self.assertEqual(sock.recv_all(4), b'ping')
2475-
sock.send(b'pong')
2473+
incoming = ssl.MemoryBIO()
2474+
outgoing = ssl.MemoryBIO()
2475+
sslobj = sslctx.wrap_bio(incoming, outgoing, server_side=True)
2476+
2477+
while True:
2478+
try:
2479+
sslobj.do_handshake()
2480+
except ssl.SSLWantReadError:
2481+
if outgoing.pending:
2482+
sock.send(outgoing.read())
2483+
incoming.write(sock.recv(16384))
2484+
else:
2485+
if outgoing.pending:
2486+
sock.send(outgoing.read())
2487+
break
2488+
2489+
incoming.write(sock.recv(16384))
2490+
self.assertEqual(sslobj.read(4), b'ping')
2491+
sslobj.write(b'pong')
2492+
sock.send(outgoing.read())
24762493

24772494
time.sleep(0.2) # wait for the peer to fill its backlog
24782495

24792496
# send close_notify but don't wait for response
2480-
sock.setblocking(0)
24812497
with self.assertRaises(ssl.SSLWantReadError):
2482-
sock.unwrap()
2483-
sock.setblocking(1)
2498+
sslobj.unwrap()
2499+
sock.send(outgoing.read())
24842500

24852501
# should receive all data
2486-
data = sock.recv_all(CHUNK * SIZE)
2487-
self.assertEqual(len(data), CHUNK * SIZE)
2502+
data_len = 0
2503+
while True:
2504+
try:
2505+
chunk = len(sslobj.read(16384))
2506+
data_len += chunk
2507+
except ssl.SSLWantReadError:
2508+
incoming.write(sock.recv(16384))
2509+
except ssl.SSLZeroReturnError:
2510+
break
24882511

2489-
# wait for close_notify
2490-
sock.unwrap()
2512+
self.assertEqual(data_len, CHUNK * SIZE)
2513+
2514+
# verify that close_notify is received
2515+
sslobj.unwrap()
24912516

24922517
sock.close()
24932518

uvloop/sslproto.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ class SSLProtocol(object):
328328
self._app_transport = None
329329
self._wakeup_waiter(exc)
330330

331+
if getattr(self, '_shutdown_timeout_handle', None):
332+
self._shutdown_timeout_handle.cancel()
333+
if getattr(self, '_handshake_timeout_handle', None):
334+
self._handshake_timeout_handle.cancel()
335+
331336
def get_buffer(self, n):
332337
if len(self._ssl_buffer) < n:
333338
self._ssl_buffer.extend(

0 commit comments

Comments
 (0)