-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_grpc_service.py
More file actions
74 lines (58 loc) · 3.39 KB
/
test_grpc_service.py
File metadata and controls
74 lines (58 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Tests for the nighthawk_service binary."""
import pytest
from test.integration.integration_test_fixtures import (http_test_server_fixture, server_config)
from test.integration import utility
from test.integration import asserts
def test_grpc_service_happy_flow(http_test_server_fixture):
"""Test that the gRPC service is able to execute a load test against the test server."""
http_test_server_fixture.startNighthawkGrpcService("dummy-request-source")
parsed_json, _ = http_test_server_fixture.runNighthawkClient([
"--termination-predicate", "benchmark.http_2xx:5", "--rps 10",
"--request-source %s:%s" % (http_test_server_fixture.grpc_service.server_ip,
http_test_server_fixture.grpc_service.server_port),
http_test_server_fixture.getTestServerRootUri()
])
counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
asserts.assertGreaterEqual(counters["benchmark.http_2xx"], 5)
asserts.assertEqual(counters["requestsource.internal.upstream_rq_200"], 1)
def test_grpc_service_down(http_test_server_fixture):
"""Test that the gRPC service detects that a test server is down."""
parsed_json, _ = http_test_server_fixture.runNighthawkClient([
"--rps 100",
"--request-source %s:%s" % (http_test_server_fixture.server_ip, "34589"),
http_test_server_fixture.getTestServerRootUri()
],
expect_failure=True)
counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
asserts.assertEqual(counters["requestsource.upstream_rq_pending_failure_eject"], 1)
@pytest.mark.skipif(utility.isSanitizerRun(), reason="Slow in sanitizer runs")
def test_grpc_service_stress(http_test_server_fixture):
"""Test high load."""
http_test_server_fixture.startNighthawkGrpcService("dummy-request-source")
parsed_json, _ = http_test_server_fixture.runNighthawkClient([
"--duration 100", "--rps 10000", "--concurrency 4", "--termination-predicate",
"benchmark.http_2xx:5000",
"--request-source %s:%s" % (http_test_server_fixture.grpc_service.server_ip,
http_test_server_fixture.grpc_service.server_port),
http_test_server_fixture.getTestServerRootUri()
])
counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
asserts.assertGreaterEqual(counters["benchmark.http_2xx"], 5000)
asserts.assertEqual(counters["requestsource.internal.upstream_rq_200"], 4)
def _run_service_with_args(args):
return utility.run_binary_with_args("nighthawk_service", args)
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)
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)
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)