testing sftp under windows

Robey Pointer robey at lag.net
Fri Nov 11 23:25:33 GMT 2005


On 11 Nov 2005, at 4:56, Alexey Shamrin wrote:

> On 11/11/05, Alexey Shamrin <shamrin at gmail.com> wrote:
>
> I went ahead and decided to learn a little about sockets
> (http://www.amk.ca/python/howto/sockets/ was really helpful).
>
> The problem is that under Windows socket doesn't allow invoking
> "listen" without doing "bind" first. See the patch is bellow. I had to
> add a call to self.get_transport() in test_delete and test_move
> because they would "bind", but wouldn't "close" the socket, causing
> "Address already in use" exception at the next test.

I made a couple of changes; can you verify that this works on  
Windows?  (patch is included below)  Tests still pass on posix with  
these changes too.

I changed the listen port to 0 so it can grab any port it wants, in  
case 5555 is in use.

Also I didn't like that we had to call get_transport() to make the  
test clean up correctly, so I tried having stop() (called from  
tearDown()) ensure that the socket is closed.  I think the reason  
this doesn't show up on posix is that posix sockets are closed in  
their __del__ methods.

This is checked in on my branch.

robey


=== modified file 'bzrlib/selftest/testsftp.py'
--- bzrlib/selftest/testsftp.py
+++ bzrlib/selftest/testsftp.py
@@ -54,6 +54,7 @@
          threading.Thread.__init__(self)
          self._callback = callback
          self._socket = socket.socket()
+        self._socket.bind(('localhost', 0))
          self._socket.listen(1)
          self.port = self._socket.getsockname()[1]
          self.stop_event = threading.Event()
@@ -66,6 +67,10 @@

      def stop(self):
          self.stop_event.set()
+        try:
+            self._socket.close()
+        except:
+            pass


class TestCaseWithSFTPServer (TestCaseInTempDir):






More information about the bazaar mailing list