def test_StopHangedAcceptor(self):
        ev_accepted = gevent.event.Event()
        def accept_hook(self_obj, socket, address):
            ev_accepted.set()
            gevent.sleep(999)
        TcpCmdChannel._accept = accept_hook

        cmd_channel = TcpCmdChannel('localhost', 12346, Test.CmdHandler())
        cmd_channel.start()

        sock = gevent.socket.socket()
        sock.connect(('localhost', 12346))

        assert ev_accepted.wait()
        assert not cmd_channel.stop()
    def test_StopAcceptor(self):
        ev_acceptor_started = gevent.event.Event()
        def accept_hook(self_obj, socket, address):
            ev_acceptor_started.set()
            #noinspection PyArgumentList
            self._accept_original(self_obj, socket, address)
        TcpCmdChannel._accept = accept_hook

        cmd_channel = TcpCmdChannel('localhost', 12346, Test.CmdHandler()) 
        cmd_channel.start()

        sock = gevent.socket.socket()
        sock.connect(('localhost', 12346))
        sock.sendall(struct.pack('I', 1000))

        assert ev_acceptor_started.wait()
        assert cmd_channel.stop()
 def test_StartStop(self):
     tcp_cmd_channel = TcpCmdChannel('localhost', 12346)
     tcp_cmd_channel.register_cmd_handler('anything')
     tcp_cmd_channel.start()
     tcp_cmd_channel.stop()