forked from envoyproxy/nighthawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.cc
98 lines (80 loc) · 3.2 KB
/
client_test.cc
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <chrono>
#include "external/envoy/test/test_common/environment.h"
#include "external/envoy/test/test_common/utility.h"
#include "source/client/client.h"
#include "test/client/utility.h"
#include "gtest/gtest.h"
using namespace std::chrono_literals;
using namespace testing;
namespace Nighthawk {
namespace Client {
class ClientTest : public testing::Test {};
// TODO(https://github.com/envoyproxy/nighthawk/issues/179): revisit this, and improve testability
// of the Main class, so we can mock its dependencies. We now have integration tests covering this
// much better.
// Note: these tests do not have a backend set up to talk to.
// That's why we expect exit codes indicating failure.
TEST_F(ClientTest, NormalRun) {
Main program(Nighthawk::Client::TestUtility::createOptionsImpl(
"foo --duration 1 --rps 10 http://localhost:63657/"));
EXPECT_FALSE(program.run());
}
TEST_F(ClientTest, AutoConcurrencyRun) {
// See the comment in TestUtility::createOptionsImpl()
TCLAP::OptionalUnlabeledTracker::alreadyOptional() = false;
std::vector<const char*> argv;
argv.push_back("foo");
argv.push_back("--concurrency");
argv.push_back("auto");
argv.push_back("--duration");
argv.push_back("1");
argv.push_back("--rps");
argv.push_back("1");
argv.push_back("--verbosity");
argv.push_back("error");
argv.push_back("--simple-warmup");
argv.push_back("http://localhost:63657/");
Main program(argv.size(), argv.data());
EXPECT_FALSE(program.run());
}
// TODO(https://github.com/envoyproxy/nighthawk/issues/140):
// This is just for coverage, and we do not care where any traffic we send ends it or what that
// looks like. We do functional testing in python now, but unfortunately any code we hit there isn't
// counted as code-coverage. Ideally, the code hit during the python test runs would count for
// coverage, and we use unit-tests here to hit any edge cases we can't easily hit otherwise.
TEST_F(ClientTest, TracingRun) {
// See the comment in TestUtility::createOptionsImpl()
TCLAP::OptionalUnlabeledTracker::alreadyOptional() = false;
std::vector<const char*> argv;
argv.push_back("foo");
argv.push_back("--duration");
argv.push_back("5");
argv.push_back("--rps");
argv.push_back("10");
argv.push_back("--verbosity");
argv.push_back("error");
argv.push_back("http://localhost:63657/");
argv.push_back("--trace");
argv.push_back("zipkin://localhost:9411/api/v2/spans");
Main program(argv.size(), argv.data());
EXPECT_FALSE(program.run());
}
TEST_F(ClientTest, BadRun) {
Main program(Nighthawk::Client::TestUtility::createOptionsImpl(
"foo --duration 1 --rps 1 https://unresolveable.host/"));
EXPECT_FALSE(program.run());
}
TEST_F(ClientTest, BadRemoteRun) {
Main program(Nighthawk::Client::TestUtility::createOptionsImpl(
"foo --duration 1 --nighthawk-service grpc://unresolveable.host:8843 --rps 1 "
"http://localhost:63657/"));
EXPECT_FALSE(program.run());
}
TEST_F(ClientTest, RemoteRun) {
Main program(Nighthawk::Client::TestUtility::createOptionsImpl(
"foo --duration 1 --nighthawk-service grpc://localhost:8843 --rps 1 "
"http://localhost:63657/"));
EXPECT_FALSE(program.run());
}
} // namespace Client
} // namespace Nighthawk