Rev 3519: Tests passing for python2.5 and python2.6 (and python2.4 :). in file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Mar 2 14:26:06 GMT 2009
At file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/
------------------------------------------------------------
revno: 3519
revision-id: v.ladeuil+lp at free.fr-20090302142604-guy21k12jikewl37
parent: v.ladeuil+lp at free.fr-20090301100200-1qdmf362uw5q35s0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: pyftpdlib
timestamp: Mon 2009-03-02 15:26:04 +0100
message:
Tests passing for python2.5 and python2.6 (and python2.4 :).
* bzrlib/tests/ftp_server/pyftpdlib_based.py:
(BzrConformingFS.fs2ftp): Fix the cause of the remaining failing
tests.
(FTPServer.setUp, FTPServer.tearDown): Better server handling,
avoiding socket leaks, hangs and other weirdness. Requires a patch
upstream though.
-------------- next part --------------
=== modified file 'bzrlib/tests/ftp_server/pyftpdlib_based.py'
--- a/bzrlib/tests/ftp_server/pyftpdlib_based.py 2009-03-01 10:02:00 +0000
+++ b/bzrlib/tests/ftp_server/pyftpdlib_based.py 2009-03-02 14:26:04 +0000
@@ -54,6 +54,15 @@
# paths is better handled. -- vila 20090228
return [str(s) for s in os.listdir(path)]
+ def fs2ftp(self, fspath):
+ p = ftpserver.AbstractedFS.fs2ftp(self, fspath)
+ # We should never send unicode strings, they are not handled properly
+ # by the stack (asynchat.async_chat.initiate_send using a buffer()
+ # starting with python2.6 may be the real culprit, but converting to
+ # str() here fixes the problem. that may need to be revisited once
+ # unicode or at least utf-8 encoded paths is better handled. -- vila
+ # 20090228
+ return str(p)
class BZRConformingFTPHandler(ftpserver.FTPHandler):
@@ -122,6 +131,8 @@
def __init__(self, address, handler, authorizer):
ftpserver.FTPServer.__init__(self, address, handler)
self.authorizer = authorizer
+ # Worth backporting updstream ?
+ self.addr = self.socket.getsockname()
class FTPServer(transport.Server):
@@ -134,6 +145,7 @@
self._async_thread = None
# ftp server logs
self.logs = []
+ self._ftpd_running = False
def get_url(self):
"""Calculate an ftp url to this server."""
@@ -172,31 +184,21 @@
# Don't let it loop forever, or handle an infinite number of requests.
# In this case it will run for 1000s, or 10000 requests
self._async_thread = threading.Thread(
- target=self._asyncore_loop_ignore_EBADF,
- kwargs={'timeout':0.1,
- 'count':100000,
- })
- self._async_thread.setDaemon(True)
+ target=self._run_server,)
self._async_thread.start()
def tearDown(self):
"""See bzrlib.transport.Server.tearDown."""
- self._ftp_server.close_all()
+ # Tell the server to stop
+ self._ftpd_running = False
+ # But also close the server socket for tests that start the server but
+ # never initiate a connection.
+ self._ftp_server.close()
self._async_thread.join()
- def _asyncore_loop_ignore_EBADF(self, *args, **kwargs):
- """Ignore EBADF during server shutdown.
-
- We close the socket to get the server to shutdown, but this causes
- select.select() to raise EBADF.
+ def _run_server(self):
+ """Run the server until tearDown is called, shut it down properly then.
"""
- try:
- self._ftp_server.serve_forever(*args, **kwargs)
- # FIXME: If we reach that point, we should raise an exception
- # explaining that the 'count' parameter in setUp is too low or
- # testers may wonder why their test just sits there waiting for a
- # server that is already dead. Note that if the tester waits too
- # long under pdb the server will also die.
- except select.error, e:
- if e.args[0] != errno.EBADF:
- raise
+ self._ftpd_running = True
+ self._ftp_server.serve_forever(timeout=0.1, count=10000,
+ until=lambda : not self._ftpd_running)
More information about the bazaar-commits
mailing list