示例#1
0
    def test_reservation_server_multi(self):
        """Test reservation server, expecting multiple reservations"""
        num_clients = 4
        s = Server(num_clients)
        addr = s.start()

        def reserve(num):
            c = Client(addr)
            # time.sleep(random.randint(0,5))     # simulate varying start times
            resp = c.register({'node': num})
            self.assertEqual(resp, 'OK')
            c.await_reservations()
            c.close()

        # start/register clients
        threads = [None] * num_clients
        for i in range(num_clients):
            threads[i] = threading.Thread(target=reserve, args=(i, ))
            threads[i].start()

        # wait for clients to complete
        for i in range(num_clients):
            threads[i].join()
        print("all done")

        # get list of reservations
        c = Client(addr)
        reservations = c.get_reservations()
        self.assertEqual(len(reservations), num_clients)

        # request server stop
        c.request_stop()
        time.sleep(1)
        self.assertEqual(s.done, True)
    def test_reservation_server_multi(self):
        # start reservation server expecting num_clients reservations
        num_clients = 4
        s = Server(num_clients)
        addr = s.start()

        def reserve(num):
            c = Client(addr)
            #time.sleep(random.randint(0,5))     # simulate varying start times
            resp = c.register({'node':num})
            self.assertEqual(resp, 'OK')
            c.await_reservations()
            c.close()

        # start/register clients
        threads = [None] * num_clients
        for i in range(num_clients):
            threads[i] = threading.Thread(target=reserve, args=(i,))
            threads[i].start()

        # wait for clients to complete
        for i in range(num_clients):
            threads[i].join()
        print("all done")

        # get list of reservations
        c = Client(addr)
        reservations = c.get_reservations()
        self.assertEquals(len(reservations), num_clients)

        # request server stop
        c.request_stop()
        self.assertEquals(s.done, True)
  def test_reservation_server(self):
    """Test reservation server, expecting 1 reservation"""
    s = Server(1)
    addr = s.start()

    # add first reservation
    c = Client(addr)
    resp = c.register({'node': 1})
    self.assertEqual(resp, 'OK')

    # get list of reservations
    reservations = c.get_reservations()
    self.assertEqual(len(reservations), 1)

    # should return immediately with list of reservations
    reservations = c.await_reservations()
    self.assertEqual(len(reservations), 1)

    # request server stop
    c.request_stop()
    self.assertEqual(s.done, True)
    def test_reservation_server(self):
        # start reservation server expecting 1 reservation
        s = Server(1)
        addr = s.start()

        # add first reservation
        c = Client(addr)
        resp = c.register({'node':1})
        self.assertEqual(resp, 'OK')

        # get list of reservations
        reservations = c.get_reservations()
        self.assertEquals(len(reservations), 1)

        # should return immediately with list of reservations
        reservations = c.await_reservations()
        self.assertEquals(len(reservations), 1)

        # request server stop
        c.request_stop()
        self.assertEquals(s.done, True)
 def test_reservation_enviroment_not_exists_start_listening_socket_return_socket(self):
   tfos_server = Server(1)
   print(tfos_server.start_listening_socket().getsockname()[1])
   assert type(tfos_server.start_listening_socket().getsockname()[1]) == int
 def test_reservation_enviroment_exists_start_listening_socket_return_socket_listening_to_environment_port_value(self):
   tfos_server = Server(1)
   with mock.patch.dict(os.environ, {'TFOS_SERVER_PORT': '9999'}):
     assert tfos_server.start_listening_socket().getsockname()[1] == 9999
 def test_reservation_enviroment_not_exists_get_server_ip_return_actual_host_ip(self):
   tfos_server = Server(5)
   assert tfos_server.get_server_ip() == util.get_ip_address()
 def test_reservation_enviroment_exists_get_server_ip_return_environment_value(self):
     tfos_server = Server(5)
     with mock.patch.dict(os.environ, {'TFOS_SERVER_HOST': 'my_host_ip'}):
       assert tfos_server.get_server_ip() == "my_host_ip"