示例#1
0
    def testMembers(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        members = ["close", "client_addr", "server_port", "ssl", "socket", "start_time"]
        for m in members:
            self.assertTrue(hasattr(c, m),
                         msg="Connection object does not have %s " % m)
示例#2
0
    def testSocketSend(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        RECVD_DATA = "this is a test"
        c.send(RECVD_DATA)

        data = self.sock.recv(len(RECVD_DATA))

        self.assertEqual(data, RECVD_DATA)
示例#3
0
    def testSocketRecv(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        SENT_DATA = "this is a test"
        self.sock.send(SENT_DATA)

        data = c.recv(len(SENT_DATA))

        self.assertEqual(data, SENT_DATA)
示例#4
0
    def testFileLikeSocketRead(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        SENT_DATA = "this is a test"
        self.sock.send(SENT_DATA)

        f = c.makefile()
        data = f.read(len(SENT_DATA))

        self.assertEqual(data, SENT_DATA)

        f.close()
示例#5
0
    def testFileLikeSocketReadline(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        SENT_DATA = """this is a test\r\nthis is another line\r\n"""
        self.sock.send(SENT_DATA)

        time.sleep(0.25)

        f = c.makefile()

        for l in SENT_DATA.splitlines():
            data = f.readline()
            self.assertEqual(data, l + "\r\n")

        f.close()
示例#6
0
    def testFileLikeSocketReadlines(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        SENT_DATA = """this is a test\r\nthis is another line\r\n"""
        self.sock.send(SENT_DATA)
        self.sock.close()

        time.sleep(0.25)

        f = c.makefile()

        sent_lines = [x + '\r\n' for x in SENT_DATA.splitlines()]
        data_lines = f.readlines()

        self.assertEqual(sent_lines, data_lines)

        f.close()
示例#7
0
    def testFileLikeSocketReadline(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        SENT_DATA = b("""this is a test\nthis is another line\n""")
        self.sock.send(SENT_DATA)

        time.sleep(0.25)

        f = c.makefile()

        try:
            for l in SENT_DATA.splitlines():
                data = b(f.readline())
                self.assertEqual(data, l+b("\n"))
        finally:
            f.close()
            c.close()
示例#8
0
    def testMonitor(self):
        self.testNotActive()  # create self.monitor

        # Start the listener
        self.listener = listener.Listener(self.interface, 5, self.active_queue)
        self.listener.start()

        # Create a socket connecting to listener's port
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(15)
        sock.connect(self.interface)

        # Verify that listener put it in the active queue
        self._waitForEqual(self.active_queue.qsize, 1)
        self.assertEqual(self.active_queue.qsize(), 1)

        self.monitor.start()

        # Put it in the monitor queue
        conn = self.active_queue.get()
        conn = connection.Connection(*conn)
        self.monitor_queue.put(conn)
        self._waitForEqual(self.monitor_queue.qsize, 1)
        self.assertEqual(self.monitor_queue.qsize(), 1)

        # Wait for the monitor queue to see it
        self._waitForEqual(self.monitor_queue.qsize, 0)
        self.assertEqual(self.monitor_queue.qsize(), 0)

        # Send something to the socket to see if it gets put back on the active
        # queue.
        sock.send(b("test data"))
        sock.close()

        # Give monitor a chance to see it
        self._waitForEqual(self.active_queue.qsize, 1)

        # Finally check to make sure that it's on the active queue
        self.assertEqual(self.active_queue.qsize(), 1)
        conn2 = self.active_queue.get()
        self.assertTrue(conn is conn2)
示例#9
0
    def testSocketTimeout(self):
        c = connection.Connection(*(self.server.active_queue.get(timeout=10)))

        timeout = c.socket.gettimeout()
        self.assertEqual(timeout, SOCKET_TIMEOUT)