def test_https_h1_sni(https_test_server_fixture):
  """Test that SNI indication works on https/h1."""
  # Verify success when we set the right host
  parsed_json, _ = https_test_server_fixture.runNighthawkClient([
      https_test_server_fixture.getTestServerRootUri(), "--rps", "100", "--duration", "100",
      "--termination-predicate", "benchmark.http_2xx:2", "--request-header", "host: sni.com"
  ])
  counters = https_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
  asserts.assertCounterGreaterEqual(counters, "benchmark.http_2xx", 1)
  # It is possible that the # of upstream_cx > # of backend connections for H1
  # as new connections will spawn if the existing clients cannot keep up with the RPS.
  asserts.assertCounterGreaterEqual(counters, "upstream_cx_http1_total", 1)
  asserts.assertCounterGreaterEqual(counters, "ssl.handshake", 1)

  # Verify failure when we set no host (will get plain http)
  parsed_json, _ = https_test_server_fixture.runNighthawkClient(
      [https_test_server_fixture.getTestServerRootUri(), "--rps", "20", "--duration", "100"],
      expect_failure=True)

  # Verify success when we use plain http and don't request the sni host
  parsed_json, _ = https_test_server_fixture.runNighthawkClient([
      https_test_server_fixture.getTestServerRootUri().replace("https://", "http://"), "--rps",
      "100", "--duration", "20", "--termination-predicate", "benchmark.http_2xx:2"
  ],
                                                                expect_failure=False)

  counters = https_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
  asserts.assertCounterGreaterEqual(counters, "benchmark.http_2xx", 1)
  # It is possible that the # of upstream_cx > # of backend connections for H1
  # as new connections will spawn if the existing clients cannot keep up with the RPS.
  asserts.assertCounterGreaterEqual(counters, "upstream_cx_http1_total", 1)
  asserts.assertNotIn("ssl.handshake", counters)
def test_http_h1_mini_stress_test_without_client_side_queueing(http_test_server_fixture):
  """Run a max rps test with the h1 pool against our test server, with no client-side queueing."""
  counters = _mini_stress_test(http_test_server_fixture, [
      http_test_server_fixture.getTestServerRootUri(), "--rps", "999999", "--connections", "1",
      "--duration", "100", "--termination-predicate", "benchmark.http_2xx:99"
  ])
  asserts.assertCounterEqual(counters, "upstream_rq_pending_total", 1)
  asserts.assertNotIn("upstream_cx_overflow", counters)
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_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 3 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 = 8 seconds.
  (the pool drain timeout is hard coded to 5 seconds as of writing this).
  """
  t0 = time.time()
  parsed_json, _ = https_test_server_fixture.runNighthawkClient([
      https_test_server_fixture.getTestServerRootUri(), "--rps", "100", "--duration", "3",
      "--request-header", "x-nighthawk-test-server-config: {static_delay: \"100s\"}"
  ])
  t1 = time.time()
  time_delta = t1 - t0
  counters = https_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
  assert time_delta < 40  # *lots* of slack to avoid failure in slow CI executions.
  asserts.assertCounterGreaterEqual(counters, "upstream_cx_http1_total", 1)
  asserts.assertNotIn("benchmark.http_2xx", counters)
Пример #7
0
def test_h1_pool_strategy(http_test_server_fixture):
    """Test connection re-use strategies of the http 1 connection pool.

  Test that with the "mru" strategy only the first created connection gets to send requests.
  Then, with the "lru" strategy, we expect the other connection to be used as well.
  """
    def countLogLinesWithSubstring(logs, substring):
        return len(
            [line for line in logs.split(os.linesep) if substring in line])

    _, logs = http_test_server_fixture.runNighthawkClient([
        "--rps 5", "-v", "trace", "--connections", "2",
        "--prefetch-connections",
        "--experimental-h1-connection-reuse-strategy", "mru",
        "--termination-predicate", "benchmark.http_2xx:4",
        http_test_server_fixture.getTestServerRootUri()
    ])

    asserts.assertNotIn("[C1] message complete", logs)
    asserts.assertEqual(
        countLogLinesWithSubstring(logs, "[C0] message complete"), 10)

    requests = 12
    connections = 3
    _, logs = http_test_server_fixture.runNighthawkClient([
        "--rps", "5", "-v trace", "--connections",
        str(connections), "--prefetch-connections",
        "--experimental-h1-connection-reuse-strategy", "lru",
        "--termination-predicate",
        "benchmark.http_2xx:%d" % (requests - 1),
        http_test_server_fixture.getTestServerRootUri()
    ])
    for i in range(1, connections):
        line_count = countLogLinesWithSubstring(logs,
                                                "[C%d] message complete" % i)
        strict_count = (requests / connections) * 2
        asserts.assertBetweenInclusive(line_count, strict_count, strict_count)