def test_Cancel_On_ClientDisconnect(self): ev_cancel = gevent.event.Event() ev_new = gevent.event.Event() with TcpCmdChannel('localhost', 12346, Test.CmdHandler(ev_new, ev_cancel)): sock = gevent.socket.socket() sock.connect(('localhost', 12346)) common.send_new_query(sock, common.SAT_QUERY_SMT) assert ev_new.wait(5) sock.close() assert ev_cancel.wait(5)
def test_new_cancel_new_cancel(self): port = 18982 server_g = gevent.spawn(self.server_func, port) gevent.sleep(1) #ensure server starts sock = gevent.socket.socket() sock.connect(('localhost', port)) id = common.send_new_query(sock, common.SAT_QUERY_KLEE) common.send_cancel_query(sock, id) id = common.send_new_query(sock, common.SAT_QUERY_KLEE) common.send_cancel_query(sock, id) team_solver.run_server.sigint_handler() server_g.join()
def client_func(self, port, number_of_queries=1, random_close=False): sock = gevent.socket.socket() sock.connect(('127.0.0.1', port)) for _ in range(1, number_of_queries): id = common.send_new_query(sock, common.SAT_QUERY_KLEE) if random_close and random.random() > 1/2.: break common.send_cancel_query(sock, id) id = common.send_new_query(sock, common.SAT_QUERY_KLEE) reply = None while True: reply = ReplyMessage() common.recv_to_message(sock, reply) if reply.cmdId == id: #there might be an outdated messages break assert reply.type == ReplyMessage.SAT common.assert_sat_ser_assignments(reply.sat.assignment, common.SAT_QUERY_ASSIGNMENT_SERIALIZED_KLEE) sock.close()
def test_SendResult(self): self.uniq_query = None self.ev_new = gevent.event.Event() def on_new(u_q): assert u_q is not None self.uniq_query = u_q self.ev_new.set() with TcpCmdChannel('localhost', 12346, Test.CmdHandlerFunc(on_new)) as tcp_cmd_channel: assert tcp_cmd_channel is not None sock = gevent.socket.socket() sock.connect(('localhost', 12346)) common.send_new_query(sock, common.SAT_QUERY_SMT) assert self.ev_new.wait(5) assert self.uniq_query is not None result = SolverResult(self.uniq_query, True, {'some solver': '1212'}, {'arr':[0, 1, 2, 3]}) assert tcp_cmd_channel is not None tcp_cmd_channel.send_result(result) common.recv_to_message(sock, ReplyMessage())
def test_CmdHandler(self): ev_cancel = gevent.event.Event() ev_new = gevent.event.Event() with TcpCmdChannel('localhost', 12346, Test.CmdHandler(ev_new, ev_cancel)): sock = gevent.socket.socket() sock.connect(('localhost', 12346)) for _ in range(1, 5): ev_new.clear() ev_cancel.clear() id = common.send_new_query(sock, common.SAT_QUERY_SMT) assert ev_new.wait(5) common.send_cancel_query(sock, id) assert ev_cancel.wait(5)