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 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)
    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()