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 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)
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
def test_daemon_report_port(self): daemon = IbisServerNode(server_port=self.server_port) exceptions = [] def f(): try: daemon.report_daemon() except Exception as e: exceptions.append(str(e)) t = threading.Thread(target=f) t.start() self._acknowledge_process() t.join() self.assertEqual(len(exceptions), 0) t = threading.Thread(target=f) t.start() sock, _ = self.server_sock.accept() sock.recv(1024) sock.send('not ok') sock.close() t.join() self.assertEqual(len(exceptions), 1)