Ejemplo n.º 1
0
def run_test(args):
    test_cases = _parse_weighted_test_cases(args.test_cases)
    test_server_targets = args.server_addresses.split(',')
    # Propagate any client exceptions with a queue
    exception_queue = queue.Queue()
    stop_event = threading.Event()
    hist = histogram.Histogram(1, 1)
    runners = []

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=25))
    metrics_pb2.add_MetricsServiceServicer_to_server(
        metrics_server.MetricsServer(hist), server)
    server.add_insecure_port('[::]:{}'.format(args.metrics_port))
    server.start()

    for test_server_target in test_server_targets:
        for _ in xrange(args.num_channels_per_server):
            channel = grpc.insecure_channel(test_server_target)
            for _ in xrange(args.num_stubs_per_channel):
                stub = test_pb2.TestServiceStub(channel)
                runner = test_runner.TestRunner(stub, test_cases, hist,
                                                exception_queue, stop_event)
                runners.append(runner)

    for runner in runners:
        runner.start()
    try:
        timeout_secs = args.test_duration_secs
        if timeout_secs < 0:
            timeout_secs = None
        raise exception_queue.get(block=True, timeout=timeout_secs)
    except queue.Empty:
        # No exceptions thrown, success
        pass
    finally:
        stop_event.set()
        for runner in runners:
            runner.join()
        runner = None
        server.stop(None)
Ejemplo n.º 2
0
def run_test(args):
  test_cases = _parse_weighted_test_cases(args.test_cases)
  test_servers = args.server_addresses.split(',')
  # Propagate any client exceptions with a queue
  exception_queue = queue.Queue()
  stop_event = threading.Event()
  hist = histogram.Histogram(1, 1)
  runners = []

  server = metrics_pb2.beta_create_MetricsService_server(
      metrics_server.MetricsServer(hist))
  server.add_insecure_port('[::]:{}'.format(args.metrics_port))
  server.start()

  for test_server in test_servers:
    host, port = test_server.split(':', 1)
    for _ in xrange(args.num_channels_per_server):
      channel = implementations.insecure_channel(host, int(port))
      for _ in xrange(args.num_stubs_per_channel):
        stub = test_pb2.beta_create_TestService_stub(channel)
        runner = test_runner.TestRunner(stub, test_cases, hist,
                                        exception_queue, stop_event)
        runners.append(runner)

  for runner in runners:
    runner.start()
  try:
    timeout_secs = args.test_duration_secs
    if timeout_secs < 0:
      timeout_secs = None
    raise exception_queue.get(block=True, timeout=timeout_secs)
  except queue.Empty:
    # No exceptions thrown, success
    pass
  finally:
    stop_event.set()
    for runner in runners:
      runner.join()
      runner = None
    server.stop(0)