def test_multiple_backends_https_h1(multi_https_test_server_fixture):
  """Test that we can load-test multiple backends on https.

  Runs the CLI configured to use HTTP/1 with TLS against multiple test servers, and sanity
  checks statistics from both client and server.
  """
  nighthawk_client_args = [
      "--multi-target-use-https", "--multi-target-path", "/", "--duration", "100",
      "--termination-predicate", "benchmark.http_2xx:24"
  ]
  for uri in multi_https_test_server_fixture.getAllTestServerRootUris():
    nighthawk_client_args.append("--multi-target-endpoint")
    nighthawk_client_args.append(uri.replace("https://", "").replace("/", ""))

  parsed_json, stderr = multi_https_test_server_fixture.runNighthawkClient(nighthawk_client_args)

  counters = multi_https_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
  asserts.assertCounterEqual(counters, "benchmark.http_2xx", 25)
  asserts.assertCounterEqual(counters, "upstream_cx_http1_total", 3)
  asserts.assertCounterGreater(counters, "upstream_cx_rx_bytes_total", 0)
  asserts.assertCounterEqual(counters, "upstream_cx_total", 3)
  asserts.assertCounterGreater(counters, "upstream_cx_tx_bytes_total", 0)
  asserts.assertCounterEqual(counters, "upstream_rq_pending_total", 3)
  asserts.assertCounterEqual(counters, "upstream_rq_total", 25)
  asserts.assertCounterEqual(counters, "default.total_match_count", 3)
  total_2xx = 0
  for parsed_server_json in multi_https_test_server_fixture.getAllTestServerStatisticsJsons():
    single_2xx = multi_https_test_server_fixture.getServerStatFromJson(
        parsed_server_json, "http.ingress_http.downstream_rq_2xx")
    asserts.assertBetweenInclusive(single_2xx, 8, 9)
    total_2xx += single_2xx
  asserts.assertBetweenInclusive(total_2xx, 24, 25)
def test_h1_pool_strategy_lru(http_test_server_fixture):
    """Test connection re-use strategies of the http 1 connection pool.

  Test that with the "least recently used" (lru) strategy all connections are used with roughly equal distribution.
  """
    requests = 12
    connections = 3
    _, logs = http_test_server_fixture.runNighthawkClient([
        "--rps",
        "5",
        "-v trace",
        "--duration",
        "20",
        "--connections",
        str(connections),
        "--prefetch-connections",
        "--experimental-h1-connection-reuse-strategy",
        "lru",
        "--termination-predicate",
        # termination-predicate takes affect when it exceeds the limit. Therefore, set the limit to 1 less than the desired number of requests.
        "benchmark.http_2xx:%d" % (requests - 1),
        http_test_server_fixture.getTestServerRootUri()
    ])

    line_counts = []
    for i in range(1, connections):
        line_counts.append(
            float(
                utility.count_log_lines_with_substring(
                    logs, "[C%d] message complete" % i)))

    average_line_count = sum(line_counts) / len(line_counts)
    for line_count in line_counts:
        asserts.assertBetweenInclusive(
            line_count,
            # provide a little slack. Minimum of 2 as envoy logs "message complete" twice per request.
            average_line_count - 2,
            average_line_count + 2)
示例#3
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)