giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.65k stars 267 forks source link

TestFtpStoreDataTLSMixin.test_rest_on_stor and TestFtpStoreDataTLSMixin.test_stor_ascii fail #512

Closed sbraz closed 4 years ago

sbraz commented 4 years ago

Hi, I don't know what triggers this but those tests don't pass any more on my systems (Gentoo and Arch tested).

Here is the original bug report: https://bugs.gentoo.org/701146

I can reproduce it with the master branch with PYTHONPATH=. pytest -vv pyftpdlib/test/test_functional_ssl.py::TestFtpStoreDataTLSMixin::test_rest_on_stor pyftpdlib/test/test_functional_ssl.py::TestFtpStoreDataTLSMixin::test_stor_ascii:

============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-4.6.6, py-1.8.0, pluggy-0.13.0 -- /usr/bin/python3.6
cachedir: .pytest_cache
rootdir: /tmp/pyftpdlib
plugins: backports.unittest-mock-1.5
collecting ... collected 2 items

pyftpdlib/test/test_functional_ssl.py::TestFtpStoreDataTLSMixin::test_rest_on_stor <- pyftpdlib/test/test_functional.py FAILED [ 50%]
pyftpdlib/test/test_functional_ssl.py::TestFtpStoreDataTLSMixin::test_stor_ascii <- pyftpdlib/test/test_functional.py FAILED [100%]

=================================== FAILURES ===================================
__________________ TestFtpStoreDataTLSMixin.test_rest_on_stor __________________

self = <pyftpdlib.test.test_functional_ssl.TestFtpStoreDataTLSMixin testMethod=test_rest_on_stor>

    def test_rest_on_stor(self):
        # Test STOR preceded by REST.
        data = b'abcde12345' * 100000
        self.dummy_sendfile.write(data)
        self.dummy_sendfile.seek(0)

        self.client.voidcmd('TYPE I')
        with contextlib.closing(
                self.client.transfercmd('stor ' + TESTFN)) as conn:
            bytes_sent = 0
            while True:
                chunk = self.dummy_sendfile.read(BUFSIZE)
                conn.sendall(chunk)
                bytes_sent += len(chunk)
                # stop transfer while it isn't finished yet
                if bytes_sent >= INTERRUPTED_TRANSF_SIZE or not chunk:
                    break

        # transfer wasn't finished yet but server can't know this,
        # hence expect a 226 response
        self.assertEqual('226', self.client.voidresp()[:3])

        # resuming transfer by using a marker value greater than the
        # file size stored on the server should result in an error
        # on stor
        file_size = self.client.size(TESTFN)
>       self.assertEqual(file_size, bytes_sent)
E       AssertionError: 12288 != 32768

pyftpdlib/test/test_functional.py:898: AssertionError
___________________ TestFtpStoreDataTLSMixin.test_stor_ascii ___________________

self = <pyftpdlib.test.test_functional_ssl.TestFtpStoreDataTLSMixin testMethod=test_stor_ascii>

    def test_stor_ascii(self):
        # Test STOR in ASCII mode

        def store(cmd, fp, blocksize=8192):
            # like storbinary() except it sends "type a" instead of
            # "type i" before starting the transfer
            self.client.voidcmd('type a')
            with contextlib.closing(self.client.transfercmd(cmd)) as conn:
                while True:
                    buf = fp.read(blocksize)
                    if not buf:
                        break
                    conn.sendall(buf)
            return self.client.voidresp()

        try:
            data = b'abcde12345\r\n' * 100000
            self.dummy_sendfile.write(data)
            self.dummy_sendfile.seek(0)
            store('stor ' + TESTFN, self.dummy_sendfile)
            self.client.retrbinary('retr ' + TESTFN, self.dummy_recvfile.write)
            expected = data.replace(b'\r\n', b(os.linesep))
            self.dummy_recvfile.seek(0)
            datafile = self.dummy_recvfile.read()
>           self.assertEqual(len(expected), len(datafile))
E           AssertionError: 1100000 != 1073835

pyftpdlib/test/test_functional.py:720: AssertionError
=========================== 2 failed in 0.20 seconds ===========================
giampaolo commented 4 years ago

Those tests have been unstable for years and am not sure how to fix them. :-\

DerDakon commented 4 years ago

Dupe of #500 I guess.

sbraz commented 4 years ago

Dupe of #500 I guess.

Absolutely, and yet a search for TestFtpStoreDataTLSMixin.test_rest_on_stor doesn't return it, weird.