Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions source/adaptive_load/adaptive_load_client_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,29 @@ AdaptiveLoadClientMain::AdaptiveLoadClientMain(int argc, const char* const* argv
AdaptiveLoadController& controller,
Envoy::Filesystem::Instance& filesystem)
: controller_{controller}, filesystem_{filesystem} {
TCLAP::CmdLine cmd("Adaptive Load tool that finds the optimal load on the target "
TCLAP::CmdLine cmd("Adaptive Load tool that finds the optimal load on the target " // NOLINT
"through a series of Nighthawk Service benchmarks.",
/*delimiter=*/' ', VersionInfo::version());

TCLAP::ValueArg<std::string> nighthawk_service_address(
/*flag_name=*/"", "nighthawk-service-address",
/*flag=*/"", "nighthawk-service-address",
"host:port for Nighthawk Service. To enable TLS, set --use-tls.",
/*required=*/false, "localhost:8443", "string", cmd);
/*req=*/false, "localhost:8443", "string", cmd);
TCLAP::SwitchArg use_tls(
/*flag_name=*/"", "use-tls",
/*flag=*/"", "use-tls",
"Use TLS for the gRPC connection from this program to the Nighthawk Service. Set environment "
"variable GRPC_DEFAULT_SSL_ROOTS_FILE_PATH to override the default root certificates.",
cmd);
TCLAP::ValueArg<std::string> spec_filename(
/*flag_name=*/"", "spec-file",
/*flag=*/"", "spec-file",
"Path to a textproto file describing the adaptive load session "
"(nighthawk::adaptive_load::AdaptiveLoadSessionSpec).",
/*required=*/true, /*default_value=*/"", "string", cmd);
/*req=*/true, /*val=*/"", "string", cmd);
TCLAP::ValueArg<std::string> output_filename(
/*flag_name=*/"", "output-file",
/*flag=*/"", "output-file",
"Path to write adaptive load session output textproto "
"(nighthawk::adaptive_load::AdaptiveLoadSessionOutput).",
/*required=*/true, /*default_value=*/"", "string", cmd);
/*req=*/true, /*val=*/"", "string", cmd);

Nighthawk::Utility::parseCommand(cmd, argc, argv);

Expand Down
68 changes: 34 additions & 34 deletions test/adaptive_load/adaptive_load_client_main_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ nighthawk::adaptive_load::AdaptiveLoadSessionOutput MakeBasicAdaptiveLoadSession
}

TEST(AdaptiveLoadClientMainTest, FailsWithNoInputs) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here",
};
NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(1, argv, controller, filesystem),
EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(1, argv.data(), controller, filesystem),
Nighthawk::Client::MalformedArgvException, "Required arguments missing");
}

TEST(AdaptiveLoadClientMainTest, FailsIfSpecFileNotSet) {
std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here",
"--output-file",
outfile.c_str(),
Expand All @@ -80,14 +80,14 @@ TEST(AdaptiveLoadClientMainTest, FailsIfSpecFileNotSet) {
NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(3, argv, controller, filesystem),
EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(3, argv.data(), controller, filesystem),
Nighthawk::Client::MalformedArgvException,
"Required argument missing: spec-file");
}

TEST(AdaptiveLoadClientMainTest, FailsIfOutputFileNotSet) {
std::string infile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here",
"--spec-file",
infile.c_str(),
Expand All @@ -96,22 +96,22 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOutputFileNotSet) {
NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain main(3, argv, controller, filesystem),
EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain main(3, argv.data(), controller, filesystem),
Nighthawk::Client::MalformedArgvException,
"Required argument missing: output-file");
}

TEST(AdaptiveLoadClientMainTest, FailsWithNonexistentInputFile) {
std::string infile = Nighthawk::TestEnvironment::runfilesPath("nonexistent.textproto");
std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(),
};

NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException,
"Failed to read spec textproto file");
}
Expand All @@ -120,14 +120,14 @@ TEST(AdaptiveLoadClientMainTest, FailsWithUnparseableInputFile) {
std::string infile = Nighthawk::TestEnvironment::runfilesPath(
"test/adaptive_load/test_data/invalid_session_spec.textproto");
std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(),
};

NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to parse file");
}

Expand All @@ -136,7 +136,7 @@ TEST(AdaptiveLoadClientMainTest, ExitsProcessWithNonzeroStatusOnAdaptiveControll
"test/adaptive_load/test_data/valid_session_spec.textproto");
std::string outfile = Nighthawk::TestEnvironment::runfilesPath(
"test/adaptive_load/test_data/nonexistent-dir/out.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(),
};

Expand All @@ -145,7 +145,7 @@ TEST(AdaptiveLoadClientMainTest, ExitsProcessWithNonzeroStatusOnAdaptiveControll
.WillOnce(Return(absl::DataLossError("error message")));
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_EQ(main.Run(), 1);
}

Expand All @@ -154,7 +154,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfCreatingOutputFileFails) {
"test/adaptive_load/test_data/valid_session_spec.textproto");
std::string outfile = Nighthawk::TestEnvironment::runfilesPath(
"test/adaptive_load/test_data/nonexistent-dir/out.textproto");
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(),
};

Expand All @@ -163,12 +163,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfCreatingOutputFileFails) {
.WillOnce(Return(MakeBasicAdaptiveLoadSessionOutput()));
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to open output file");
}

TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "in-dummy.textproto",
"--output-file", "out-dummy.textproto",
};
Expand All @@ -184,7 +184,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) {
std::string("test/adaptive_load/test_data/valid_session_spec.textproto")));
EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents));

NiceMock<Envoy::Filesystem::MockFile>* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
auto* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
EXPECT_CALL(filesystem, createFile(_))
.WillOnce(Return(ByMove(std::unique_ptr<NiceMock<Envoy::Filesystem::MockFile>>(mock_file))));

Expand All @@ -193,12 +193,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) {
false, Envoy::Api::IoErrorPtr(new UnknownIoError(),
[](Envoy::Api::IoError* err) { delete err; })))));

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to open output file");
}

TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "in-dummy.textproto",
"--output-file", "out-dummy.textproto",
};
Expand All @@ -214,7 +214,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) {
std::string("test/adaptive_load/test_data/valid_session_spec.textproto")));
EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents));

NiceMock<Envoy::Filesystem::MockFile>* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
auto* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
EXPECT_CALL(filesystem, createFile(_))
.WillOnce(Return(ByMove(std::unique_ptr<NiceMock<Envoy::Filesystem::MockFile>>(mock_file))));

Expand All @@ -225,13 +225,13 @@ TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) {
.WillOnce(Return(ByMove(Envoy::Api::IoCallSizeResult(
-1, Envoy::Api::IoErrorPtr(new UnknownIoError(),
[](Envoy::Api::IoError* err) { delete err; })))));
AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException,
"Unable to write to output file");
}

TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "in-dummy.textproto",
"--output-file", "out-dummy.textproto",
};
Expand All @@ -247,7 +247,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) {
std::string("test/adaptive_load/test_data/valid_session_spec.textproto")));
EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents));

NiceMock<Envoy::Filesystem::MockFile>* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
auto* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
EXPECT_CALL(filesystem, createFile(_))
.WillOnce(Return(ByMove(std::unique_ptr<NiceMock<Envoy::Filesystem::MockFile>>(mock_file))));

Expand All @@ -265,12 +265,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) {
false, Envoy::Api::IoErrorPtr(new UnknownIoError(),
[](Envoy::Api::IoError* err) { delete err; })))));

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to close output file");
}

TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "in-dummy.textproto",
"--output-file", "out-dummy.textproto",
};
Expand All @@ -287,7 +287,7 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) {
EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents));

std::string actual_outfile_contents;
NiceMock<Envoy::Filesystem::MockFile>* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
auto* mock_file = new NiceMock<Envoy::Filesystem::MockFile>;
EXPECT_CALL(filesystem, createFile(_))
.WillOnce(Return(ByMove(std::unique_ptr<NiceMock<Envoy::Filesystem::MockFile>>(mock_file))));

Expand All @@ -307,7 +307,7 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) {
.WillOnce(Return(ByMove(Envoy::Api::IoCallBoolResult(
true, Envoy::Api::IoErrorPtr(nullptr, [](Envoy::Api::IoError*) {})))));

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);
main.Run();

std::string golden_output =
Expand All @@ -317,46 +317,46 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) {
}

TEST(AdaptiveLoadClientMainTest, DefaultsToInsecureConnection) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "a", "--output-file", "b",
};

NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);

EXPECT_THAT(main.DescribeInputs(), HasSubstr("insecure"));
}

TEST(AdaptiveLoadClientMainTest, UsesTlsConnectionWhenSpecified) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--use-tls", "--spec-file", "a", "--output-file", "b",
};

NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(6, argv, controller, filesystem);
AdaptiveLoadClientMain main(6, argv.data(), controller, filesystem);

EXPECT_THAT(main.DescribeInputs(), HasSubstr("TLS"));
}

TEST(AdaptiveLoadClientMainTest, UsesDefaultNighthawkServiceAddress) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here", "--spec-file", "a", "--output-file", "b",
};

NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(5, argv, controller, filesystem);
AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem);

EXPECT_THAT(main.DescribeInputs(), HasSubstr("localhost:8443"));
}

TEST(AdaptiveLoadClientMainTest, UsesCustomNighthawkServiceAddress) {
const char* const argv[] = {
const std::vector<const char*> argv = {
"executable-name-here",
"--nighthawk-service-address",
"1.2.3.4:5678",
Expand All @@ -369,7 +369,7 @@ TEST(AdaptiveLoadClientMainTest, UsesCustomNighthawkServiceAddress) {
NiceMock<MockAdaptiveLoadController> controller;
Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest();

AdaptiveLoadClientMain main(7, argv, controller, filesystem);
AdaptiveLoadClientMain main(7, argv.data(), controller, filesystem);

EXPECT_THAT(main.DescribeInputs(), HasSubstr("1.2.3.4:5678"));
}
Expand Down