mirror of
https://github.com/python/cpython.git
synced 2025-09-29 11:45:57 +00:00
[3.12] gh-109845: Make test_ftplib more stable under load (GH-109912) (#109919)
gh-109845: Make test_ftplib more stable under load (GH-109912)
recv() can return partial data cut in the middle of a multibyte
character. Test raw binary data instead of data incorrectly decoded by parts.
(cherry picked from commit 2ef2fffe3b
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
b0e377f694
commit
1f622004c5
1 changed files with 18 additions and 20 deletions
|
@ -32,7 +32,7 @@ TIMEOUT = support.LOOPBACK_TIMEOUT
|
||||||
DEFAULT_ENCODING = 'utf-8'
|
DEFAULT_ENCODING = 'utf-8'
|
||||||
# the dummy data returned by server over the data channel when
|
# the dummy data returned by server over the data channel when
|
||||||
# RETR, LIST, NLST, MLSD commands are issued
|
# RETR, LIST, NLST, MLSD commands are issued
|
||||||
RETR_DATA = 'abcde12345\r\n' * 1000 + 'non-ascii char \xAE\r\n'
|
RETR_DATA = 'abcde\xB9\xB2\xB3\xA4\xA6\r\n' * 1000
|
||||||
LIST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n'
|
LIST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n'
|
||||||
NLST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n'
|
NLST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n'
|
||||||
MLSD_DATA = ("type=cdir;perm=el;unique==keVO1+ZF4; test\r\n"
|
MLSD_DATA = ("type=cdir;perm=el;unique==keVO1+ZF4; test\r\n"
|
||||||
|
@ -67,11 +67,11 @@ class DummyDTPHandler(asynchat.async_chat):
|
||||||
def __init__(self, conn, baseclass):
|
def __init__(self, conn, baseclass):
|
||||||
asynchat.async_chat.__init__(self, conn)
|
asynchat.async_chat.__init__(self, conn)
|
||||||
self.baseclass = baseclass
|
self.baseclass = baseclass
|
||||||
self.baseclass.last_received_data = ''
|
self.baseclass.last_received_data = bytearray()
|
||||||
self.encoding = baseclass.encoding
|
self.encoding = baseclass.encoding
|
||||||
|
|
||||||
def handle_read(self):
|
def handle_read(self):
|
||||||
new_data = self.recv(1024).decode(self.encoding, 'replace')
|
new_data = self.recv(1024)
|
||||||
self.baseclass.last_received_data += new_data
|
self.baseclass.last_received_data += new_data
|
||||||
|
|
||||||
def handle_close(self):
|
def handle_close(self):
|
||||||
|
@ -107,7 +107,7 @@ class DummyFTPHandler(asynchat.async_chat):
|
||||||
self.in_buffer = []
|
self.in_buffer = []
|
||||||
self.dtp = None
|
self.dtp = None
|
||||||
self.last_received_cmd = None
|
self.last_received_cmd = None
|
||||||
self.last_received_data = ''
|
self.last_received_data = bytearray()
|
||||||
self.next_response = ''
|
self.next_response = ''
|
||||||
self.next_data = None
|
self.next_data = None
|
||||||
self.rest = None
|
self.rest = None
|
||||||
|
@ -590,19 +590,17 @@ class TestFTPClass(TestCase):
|
||||||
self.client.abort()
|
self.client.abort()
|
||||||
|
|
||||||
def test_retrbinary(self):
|
def test_retrbinary(self):
|
||||||
def callback(data):
|
|
||||||
received.append(data.decode(self.client.encoding))
|
|
||||||
received = []
|
received = []
|
||||||
self.client.retrbinary('retr', callback)
|
self.client.retrbinary('retr', received.append)
|
||||||
self.check_data(''.join(received), RETR_DATA)
|
self.check_data(b''.join(received),
|
||||||
|
RETR_DATA.encode(self.client.encoding))
|
||||||
|
|
||||||
def test_retrbinary_rest(self):
|
def test_retrbinary_rest(self):
|
||||||
def callback(data):
|
|
||||||
received.append(data.decode(self.client.encoding))
|
|
||||||
for rest in (0, 10, 20):
|
for rest in (0, 10, 20):
|
||||||
received = []
|
received = []
|
||||||
self.client.retrbinary('retr', callback, rest=rest)
|
self.client.retrbinary('retr', received.append, rest=rest)
|
||||||
self.check_data(''.join(received), RETR_DATA[rest:])
|
self.check_data(b''.join(received),
|
||||||
|
RETR_DATA[rest:].encode(self.client.encoding))
|
||||||
|
|
||||||
def test_retrlines(self):
|
def test_retrlines(self):
|
||||||
received = []
|
received = []
|
||||||
|
@ -612,7 +610,8 @@ class TestFTPClass(TestCase):
|
||||||
def test_storbinary(self):
|
def test_storbinary(self):
|
||||||
f = io.BytesIO(RETR_DATA.encode(self.client.encoding))
|
f = io.BytesIO(RETR_DATA.encode(self.client.encoding))
|
||||||
self.client.storbinary('stor', f)
|
self.client.storbinary('stor', f)
|
||||||
self.check_data(self.server.handler_instance.last_received_data, RETR_DATA)
|
self.check_data(self.server.handler_instance.last_received_data,
|
||||||
|
RETR_DATA.encode(self.server.encoding))
|
||||||
# test new callback arg
|
# test new callback arg
|
||||||
flag = []
|
flag = []
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
|
@ -631,7 +630,8 @@ class TestFTPClass(TestCase):
|
||||||
data = RETR_DATA.replace('\r\n', '\n').encode(self.client.encoding)
|
data = RETR_DATA.replace('\r\n', '\n').encode(self.client.encoding)
|
||||||
f = io.BytesIO(data)
|
f = io.BytesIO(data)
|
||||||
self.client.storlines('stor', f)
|
self.client.storlines('stor', f)
|
||||||
self.check_data(self.server.handler_instance.last_received_data, RETR_DATA)
|
self.check_data(self.server.handler_instance.last_received_data,
|
||||||
|
RETR_DATA.encode(self.server.encoding))
|
||||||
# test new callback arg
|
# test new callback arg
|
||||||
flag = []
|
flag = []
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
|
@ -649,7 +649,7 @@ class TestFTPClass(TestCase):
|
||||||
|
|
||||||
def test_dir(self):
|
def test_dir(self):
|
||||||
l = []
|
l = []
|
||||||
self.client.dir(lambda x: l.append(x))
|
self.client.dir(l.append)
|
||||||
self.assertEqual(''.join(l), LIST_DATA.replace('\r\n', ''))
|
self.assertEqual(''.join(l), LIST_DATA.replace('\r\n', ''))
|
||||||
|
|
||||||
def test_mlsd(self):
|
def test_mlsd(self):
|
||||||
|
@ -889,12 +889,10 @@ class TestIPv6Environment(TestCase):
|
||||||
|
|
||||||
def test_transfer(self):
|
def test_transfer(self):
|
||||||
def retr():
|
def retr():
|
||||||
def callback(data):
|
|
||||||
received.append(data.decode(self.client.encoding))
|
|
||||||
received = []
|
received = []
|
||||||
self.client.retrbinary('retr', callback)
|
self.client.retrbinary('retr', received.append)
|
||||||
self.assertEqual(len(''.join(received)), len(RETR_DATA))
|
self.assertEqual(b''.join(received),
|
||||||
self.assertEqual(''.join(received), RETR_DATA)
|
RETR_DATA.encode(self.client.encoding))
|
||||||
self.client.set_pasv(True)
|
self.client.set_pasv(True)
|
||||||
retr()
|
retr()
|
||||||
self.client.set_pasv(False)
|
self.client.set_pasv(False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue