def test_cli_output_format(http_test_server_fixture):
  """Test that we observe latency percentiles with CLI output."""
  output, _ = http_test_server_fixture.runNighthawkClient(
      ["--duration 1", "--rps 10",
       http_test_server_fixture.getTestServerRootUri()], as_json=False)
  asserts.assertIn("Initiation to completion", output)
  asserts.assertIn("Percentile", output)
def test_dotted_output_format(http_test_server_fixture):
  """Test that we get the dotted string output format when requested, and ensure we get latency percentiles."""
  output, _ = http_test_server_fixture.runNighthawkClient([
      "--duration 1", "--rps 10", "--output-format dotted",
      http_test_server_fixture.getTestServerRootUri()
  ],
                                                          as_json=False)
  asserts.assertIn("global.benchmark_http_client.request_to_response.permilles-500.microseconds",
                   output)
def test_https_log_verbosity(https_test_server_fixture):
  """Test that the specified log verbosity level is respected.

  This tests for a sentinel we know is only right when the level
  is set to 'trace'.
  """
  # TODO(oschaaf): this is kind of fragile. Can we improve?
  trace_level_sentinel = "nighthawk_service_zone"
  _, logs = https_test_server_fixture.runNighthawkClient(
      ["--duration 1", "--rps 1", "-v debug",
       https_test_server_fixture.getTestServerRootUri()])
  asserts.assertNotIn(trace_level_sentinel, logs)

  _, logs = https_test_server_fixture.runNighthawkClient(
      ["--duration 1", "--rps 1", "-v trace",
       https_test_server_fixture.getTestServerRootUri()])
  asserts.assertIn(trace_level_sentinel, logs)
def test_h1_pool_strategy_mru(http_test_server_fixture):
    """Test connection re-use strategies of the http 1 connection pool.

  Test that with the "most recently used" (mru) strategy only the first created connection gets to send requests.
  """
    _, logs = http_test_server_fixture.runNighthawkClient([
        "--rps 5", "-v", "trace", "--duration", "20", "--connections", "2",
        "--prefetch-connections",
        "--experimental-h1-connection-reuse-strategy", "mru",
        "--termination-predicate", "benchmark.http_2xx:4",
        http_test_server_fixture.getTestServerRootUri()
    ])

    # Expect the second connection to not send any messages
    asserts.assertNotIn("[C1] message complete", logs)
    # Expect that we sent some traffic through the first connection
    asserts.assertIn("[C0] message complete", logs)
def test_drain(https_test_server_fixture):
  """Test that the pool drain timeout is effective, and we terminate in a timely fashion.

  Sets up the test server to delay replies 100 seconds. Our execution will only last 30 seconds, so we
  expect to observe no replies. Termination should be cut short by the drain timeout, which means
  that we should have results in approximately execution duration + drain timeout = 35 seconds.
  (the pool drain timeout is hard coded to 5 seconds as of writing this).
  If drain timeout is reached, a message will be logged to the user.
  """
  parsed_json, logs = https_test_server_fixture.runNighthawkClient([
      https_test_server_fixture.getTestServerRootUri(), "--rps", "100", "--duration", "20",
      "--request-header", "x-nighthawk-test-server-config: {static_delay: \"100s\"}"
  ])
  counters = https_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
  asserts.assertCounterGreaterEqual(counters, "upstream_cx_http1_total", 1)
  asserts.assertNotIn("benchmark.http_2xx", counters)
  asserts.assertIn("Wait for the connection pool drain timed out, proceeding to hard shutdown",
                   logs)
예제 #6
0
def test_output_transform_101():
  """Run an arbitrary load test, which outputs to json.

  This json output is then transformed to human readable output.
  """
  test_rundir = os.path.join(os.environ["TEST_SRCDIR"], os.environ["TEST_WORKSPACE"])
  process = subprocess.run([
      os.path.join(test_rundir, "nighthawk_client"), "--duration", "1", "--rps", "1", "127.0.0.1",
      "--output-format", "json"
  ],
                           stdout=subprocess.PIPE)
  output = process.stdout
  process = subprocess.run(
      [os.path.join(test_rundir, "nighthawk_output_transform"), "--output-format", "human"],
      stdout=subprocess.PIPE,
      input=output)
  asserts.assertEqual(process.returncode, 0)
  asserts.assertIn("Nighthawk - A layer 7 protocol benchmarking tool",
                   process.stdout.decode("utf-8"))
예제 #7
0
def test_client_bad_arg():
    """Test that passing bad arguments behaves as expected."""
    (exit_code, output) = _run_client_with_args("127.0.0.1 --foo")
    asserts.assertEqual(exit_code, 1)
    asserts.assertIn("PARSE ERROR: Argument: --foo", output)
예제 #8
0
def test_client_help():
    """Test that passing --help behaves as expected."""
    (exit_code, output) = _run_client_with_args("--help")
    asserts.assertEqual(exit_code, 0)
    asserts.assertIn("USAGE", output)
예제 #9
0
def test_grpc_service_nonexisting_listener_address():
    """Test that the gRPC service behaves as expected when an address is passed that it can't listen to."""
    (exit_code, output) = _run_service_with_args("--listen 1.1.1.1:1")
    asserts.assertEqual(exit_code, 1)
    asserts.assertIn("Failure: Could not start the grpc service", output)
예제 #10
0
def test_grpc_service_bad_arguments():
    """Test that the gRPC service behaves as expected with bad cli arguments."""
    (exit_code, output) = _run_service_with_args("--foo")
    asserts.assertEqual(exit_code, 1)
    asserts.assertIn("PARSE ERROR: Argument: --foo", output)
예제 #11
0
def test_grpc_service_help():
    """Test that the gRPC service behaves as expected when --help is passed."""
    (exit_code, output) = _run_service_with_args("--help")
    asserts.assertEqual(exit_code, 0)
    asserts.assertIn("USAGE", output)
예제 #12
0
def test_output_transform_bad_arguments():
  """Test that the output transform binary behaves as expected when bad arguments are passed."""
  (exit_code, output) = _run_output_transform_with_args("--foo")
  asserts.assertEqual(exit_code, 1)
  asserts.assertIn("PARSE ERROR: Argument: --foo", output)
예제 #13
0
def test_output_transform_help():
  """Test that the output transform binary behaves as expected when --help is passed."""
  (exit_code, output) = _run_output_transform_with_args("--help")
  asserts.assertEqual(exit_code, 0)
  asserts.assertIn("USAGE", output)