示例#1
0
    def test_shutdown_closes_port(self):
        daemon = IbisServerNode(server_port=self.server_port)

        t = threading.Thread(target=daemon.run_daemon)
        t.start()

        # The daemon won't actually start its main loop until the server
        # acknowledges its existence
        self._acknowledge_process()

        # Request shutdown and wait for thread to finish
        daemon.shutdown()
        t.join()
        assert port_is_closed(daemon.listen_port)
示例#2
0
class WorkerTestFixture(ImpalaServerFixture):

    def setUp(self):
        ImpalaServerFixture.setUp(self)

        self.daemon = IbisServerNode(server_port=self.server_port)

        self.daemon_t = threading.Thread(target=self.daemon.run_daemon)
        self.daemon_t.start()
        self._acknowledge_process()

    def tearDown(self):
        ImpalaServerFixture.tearDown(self)

        # Request shutdown and wait for thread to finish
        if self.daemon_t.isAlive():
            self.daemon.shutdown()
            self.daemon_t.join()

    def _connect(self, port=None):
        if port is None:
            port = self.daemon.listen_port
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(('localhost', port))
        return sock

    def _spawn_worker(self):
        if not HAVE_PSUTIL:
            pytest.skip('no psutil')

        sock = self._connect()

        # Ask to create a worker; reply OK on successful fork
        sock.send('new')
        reply = sock.recv(1024)
        assert reply == 'ok'
        sock.close()

        # Acknowledge the worker's existence
        sock, _ = self.server_sock.accept()
        msg = sock.recv(1024)
        sock.send('ok')
        sock.close()

        worker_port, worker_pid = struct.unpack('II', msg)
        proc = get_proc(worker_pid)
        assert proc.status != ('running', 'sleeping')
        return worker_port, worker_pid