Example #1
0
 def testServer_thread(self):
     daemon=ServerCallback()
     port=SU.findProbablyUnusedPort()
     serv=SocketServer_Threadpool()
     serv.init(daemon,"localhost",port)
     self.assertEqual("localhost:"+str(port), serv.locationStr)
     self.assertTrue(serv.sock is not None)
     conn=SU.SocketConnection(serv.sock, "ID12345")
     self.assertEqual("ID12345",conn.objectId)
     self.assertTrue(conn.sock is not None)
     conn.close()
     conn.close()
     self.assertFalse(conn.sock is None, "connections keep their socket object even if it's closed")
     serv.close()
     serv.close()
     self.assertTrue(serv.sock is None)
Example #2
0
 def testServer_thread(self):
     daemon = ServerCallback()
     port = SU.findProbablyUnusedPort()
     serv = SocketServer_Threadpool()
     serv.init(daemon, "localhost", port)
     self.assertEqual("localhost:" + str(port), serv.locationStr)
     self.assertIsNotNone(serv.sock)
     conn = SU.SocketConnection(serv.sock, "ID12345")
     self.assertEqual("ID12345", conn.objectId)
     self.assertIsNotNone(conn.sock)
     conn.close()
     conn.close()
     self.assertIsNotNone(conn.sock, "connections keep their socket object even if it's closed")
     serv.close()
     serv.close()
     self.assertIsNone(serv.sock)
Example #3
0
 def testServerPoolFull(self):
     port = socketutil.findProbablyUnusedPort()
     serv = SocketServer_Threadpool()
     daemon = ServerCallback()
     serv.init(daemon, "localhost", port)
     serversock = serv.sock.getsockname()
     csock1 = socketutil.createSocket(connect=serversock)
     csock2 = socketutil.createSocket(connect=serversock)
     try:
         serv.events([serv.sock])
         time.sleep(0.2)
         self.assertEqual([None], daemon.received_denied_reasons)
         serv.events([serv.sock])
         time.sleep(0.2)
         self.assertEqual(2, len(daemon.received_denied_reasons))
         self.assertIn("no free workers, increase server threadpool size", daemon.received_denied_reasons)
     finally:
         csock1.close()
         csock2.close()
         serv.shutdown()
Example #4
0
 def testServerPoolFull(self):
     port = socketutil.findProbablyUnusedPort()
     serv = SocketServer_Threadpool()
     daemon = ServerCallback()
     serv.init(daemon, "localhost", port)
     serversock = serv.sock.getsockname()
     csock1 = socketutil.createSocket(connect=serversock)
     csock2 = socketutil.createSocket(connect=serversock)
     try:
         serv.events([serv.sock])
         time.sleep(0.2)
         self.assertEqual([None], daemon.received_denied_reasons)
         serv.events([serv.sock])
         time.sleep(0.2)
         self.assertEqual(2, len(daemon.received_denied_reasons))
         self.assertIn("no free workers, increase server threadpool size", daemon.received_denied_reasons)
     finally:
         csock1.close()
         csock2.close()
         serv.shutdown()