Commits

James Lan committed ce6e0b7

fix the hanging issue on a test case failing; fix getpeername

Comments (0)

Files changed (2)

pypesocketTest.py

         svr.bind(_PipePath)
         svr.listen(5)
 
-        cli = socket.socket(socket.AF_UNIX)
-        cli.connect(_PipePath)
+        try:
+            time.sleep(0.2)  # wait server to be ready
+            cli = socket.socket(socket.AF_UNIX)
+            cli.connect(_PipePath)
 
-        sock, addr = svr.accept()
-        self.assertEqual('', sock.getpeername())
-        self.assertEqual('', addr)
-
-        sock.close()
-        cli.close()
-        svr.close()
+            try:
+                sock, addr = svr.accept()
+                self.assertEqual('', sock.getpeername())
+                self.assertEqual('', addr)
+                sock.close()
+            finally:
+                cli.close()
+        finally:
+            svr.close()
 
     @expect_socketerror(errno.ENOTCONN)
     def test_getpeername_wo_connect(self):
             raise socket.error(err)
 
     def connect_ex(self, address):
+        self._peer = address
         self.calc_pipename(address)
         timeout = 0.01
         for retry in xrange(10):
     def getpeername(self):
         if not hasattr(self, '_handle'):
             raise socket.error(errno.ENOTCONN)
-        return getattr(self, '_addr', '')
+        return getattr(self, '_peer', '')
 
     def getsockname(self):
         return getattr(self, '_addr', '')
                 else:
                     self._conn.put(pipe)
                     _kernel32.SetEvent(self.event)
-            print "listening thread finished"
+            #print "listening thread finished"
 
         self.closing = False
         self.closed = False
     def sendall(self, string, flag=0):
         written = _DWORD(0)
         _kernel32.WriteFile(self._handle, string, len(string), _byref(written), None)
-        print repr(string), written
 
     def sendto(self, string, flag=0, address=None):
         pass