From 21e8ee0083b6f261d88943a660fac59647b74d45 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Wed, 17 Mar 2021 23:24:15 +0100 Subject: [PATCH 1/2] Fix namespace dereferencing according to the style guide Just cleanup, no functional changes. Closes https://github.com/envoyproxy/nighthawk/issues/652 Signed-off-by: Otto van der Schaaf --- include/nighthawk/sink/sink.h | 6 +- .../adaptive_load_client_main.cc | 2 +- source/client/client.cc | 2 +- source/client/options_impl.cc | 2 +- source/client/service_impl.cc | 18 +- source/client/service_impl.h | 23 ++- .../common/nighthawk_service_client_impl.cc | 8 +- source/sink/nighthawk_sink_client_impl.cc | 14 +- source/sink/sink_impl.cc | 8 +- source/sink/sink_impl.h | 4 +- .../fake_metrics_plugin_test.cc | 2 +- .../fake_step_controller_test.cc | 6 +- test/adaptive_load/metrics_plugin_test.cc | 34 ++-- test/adaptive_load/plugin_loader_test.cc | 18 +- test/adaptive_load/scoring_function_test.cc | 35 ++-- test/common/nighthawk_service_client_test.cc | 9 +- .../nighthawk_distributor_client_test.cc | 187 ++++++++++++++++++ test/mocks/sink/mock_sink.h | 4 +- test/options_test.cc | 2 +- test/server/http_filter_base_test.cc | 10 +- test/service_test.cc | 6 +- test/sink/nighthawk_sink_client_test.cc | 47 +++-- test/sink/sink_test.cc | 4 +- 23 files changed, 317 insertions(+), 134 deletions(-) create mode 100644 test/distributor/nighthawk_distributor_client_test.cc diff --git a/include/nighthawk/sink/sink.h b/include/nighthawk/sink/sink.h index 857f2d6d1..c35e48dcd 100644 --- a/include/nighthawk/sink/sink.h +++ b/include/nighthawk/sink/sink.h @@ -30,17 +30,17 @@ class Sink { * @return absl::Status Indicates if the operation succeeded or not. */ virtual absl::Status - StoreExecutionResultPiece(const ::nighthawk::client::ExecutionResponse& response) const PURE; + StoreExecutionResultPiece(const nighthawk::client::ExecutionResponse& response) const PURE; /** * Attempt to load a vector of ExecutionResponse instances associated to an execution id. * * @param execution_id Specify an execution_id that the desired set of ExecutionResponse * instances are tagged with. - * @return absl::StatusOr>. + * @return absl::StatusOr>. * When no fragments are found for the provided execution id, status kNotFound is returned. */ - virtual absl::StatusOr> + virtual absl::StatusOr> LoadExecutionResult(absl::string_view execution_id) const PURE; }; diff --git a/source/adaptive_load/adaptive_load_client_main.cc b/source/adaptive_load/adaptive_load_client_main.cc index be23d1051..2dc578685 100644 --- a/source/adaptive_load/adaptive_load_client_main.cc +++ b/source/adaptive_load/adaptive_load_client_main.cc @@ -111,7 +111,7 @@ uint32_t AdaptiveLoadClientMain::Run() { throw Nighthawk::NighthawkException("Unable to parse file \"" + spec_filename_ + "\" as a text protobuf (type " + spec.GetTypeName() + ")"); } - std::shared_ptr<::grpc::Channel> channel = grpc::CreateChannel( + std::shared_ptr channel = grpc::CreateChannel( nighthawk_service_address_, use_tls_ ? grpc::SslCredentials(grpc::SslCredentialsOptions()) : grpc::InsecureChannelCredentials()); std::unique_ptr stub( diff --git a/source/client/client.cc b/source/client/client.cc index 8c08eda00..cd3d0b14f 100644 --- a/source/client/client.cc +++ b/source/client/client.cc @@ -53,7 +53,7 @@ bool Main::run() { Envoy::Event::RealTimeSystem time_system; // NO_CHECK_FORMAT(real_time) ProcessPtr process; std::unique_ptr stub; - std::shared_ptr<::grpc::Channel> channel; + std::shared_ptr channel; if (options_->nighthawkService() != "") { UriPtr uri; diff --git a/source/client/options_impl.cc b/source/client/options_impl.cc index 6cf10275b..d4c12d3da 100644 --- a/source/client/options_impl.cc +++ b/source/client/options_impl.cc @@ -592,7 +592,7 @@ OptionsImpl::OptionsImpl(const nighthawk::client::CommandLineOptions& options) { request_headers_.push_back(header_string); } if (request_options.request_method() != - ::envoy::config::core::v3::RequestMethod::METHOD_UNSPECIFIED) { + envoy::config::core::v3::RequestMethod::METHOD_UNSPECIFIED) { request_method_ = request_options.request_method(); } request_body_size_ = diff --git a/source/client/service_impl.cc b/source/client/service_impl.cc index fda3d69d7..36554e096 100644 --- a/source/client/service_impl.cc +++ b/source/client/service_impl.cc @@ -60,7 +60,7 @@ void ServiceImpl::writeResponse(const nighthawk::client::ExecutionResponse& resp } } -::grpc::Status ServiceImpl::finishGrpcStream(const bool success, absl::string_view description) { +grpc::Status ServiceImpl::finishGrpcStream(const bool success, absl::string_view description) { // We may get here while there's still an active future in-flight in the error-paths. // Allow it to wrap up and put it's response on the stream before finishing the stream. if (future_.valid()) { @@ -75,10 +75,10 @@ ::grpc::Status ServiceImpl::finishGrpcStream(const bool success, absl::string_vi // TODO(oschaaf): unit-test Process, create MockProcess & use in service_test.cc / client_test.cc // TODO(oschaaf): should we merge incoming request options with defaults? // TODO(oschaaf): aggregate the client's logs and forward them in the grpc response. -::grpc::Status ServiceImpl::ExecutionStream( - ::grpc::ServerContext* /*context*/, - ::grpc::ServerReaderWriter<::nighthawk::client::ExecutionResponse, - ::nighthawk::client::ExecutionRequest>* stream) { +grpc::Status ServiceImpl::ExecutionStream( + grpc::ServerContext* /*context*/, + grpc::ServerReaderWriter* stream) { nighthawk::client::ExecutionRequest request; stream_ = stream; @@ -122,10 +122,10 @@ RequestSourcePtr RequestSourceServiceImpl::createStaticEmptyRequestSource(const return std::make_unique(std::move(header), amount); } -::grpc::Status RequestSourceServiceImpl::RequestStream( - ::grpc::ServerContext* /*context*/, - ::grpc::ServerReaderWriter<::nighthawk::request_source::RequestStreamResponse, - ::nighthawk::request_source::RequestStreamRequest>* stream) { +grpc::Status RequestSourceServiceImpl::RequestStream( + grpc::ServerContext* /*context*/, + grpc::ServerReaderWriter* stream) { nighthawk::request_source::RequestStreamRequest request; bool ok = true; while (stream->Read(&request)) { diff --git a/source/client/service_impl.h b/source/client/service_impl.h index 760b6fb46..17cb7c3d8 100644 --- a/source/client/service_impl.h +++ b/source/client/service_impl.h @@ -45,22 +45,22 @@ class ServiceImpl final : public nighthawk::client::NighthawkService::Service, logging_context_ = std::move(logging_context); } - ::grpc::Status ExecutionStream( - ::grpc::ServerContext* context, - ::grpc::ServerReaderWriter<::nighthawk::client::ExecutionResponse, - ::nighthawk::client::ExecutionRequest>* stream) override; + grpc::Status + ExecutionStream(grpc::ServerContext* context, + grpc::ServerReaderWriter* stream) override; private: void handleExecutionRequest(const nighthawk::client::ExecutionRequest& request); void writeResponse(const nighthawk::client::ExecutionResponse& response); - ::grpc::Status finishGrpcStream(const bool success, absl::string_view description = ""); + grpc::Status finishGrpcStream(const bool success, absl::string_view description = ""); std::unique_ptr logging_context_; std::shared_ptr process_wide_; Envoy::Event::RealTimeSystem time_system_; // NO_CHECK_FORMAT(real_time) Envoy::Thread::MutexBasicLockable log_lock_; - ::grpc::ServerReaderWriter<::nighthawk::client::ExecutionResponse, - ::nighthawk::client::ExecutionRequest>* stream_; + grpc::ServerReaderWriter* stream_; std::future future_; // accepted_lock_ and accepted_event_ are used to synchronize the threads // when starting up a future to service a test, and ensure the code servicing it @@ -81,11 +81,10 @@ class RequestSourceServiceImpl final public Envoy::Logger::Loggable { public: - ::grpc::Status - RequestStream(::grpc::ServerContext* context, - ::grpc::ServerReaderWriter<::nighthawk::request_source::RequestStreamResponse, - ::nighthawk::request_source::RequestStreamRequest>* - stream) override; + grpc::Status RequestStream( + grpc::ServerContext* context, + grpc::ServerReaderWriter* stream) override; private: RequestSourcePtr createStaticEmptyRequestSource(const uint32_t amount); diff --git a/source/common/nighthawk_service_client_impl.cc b/source/common/nighthawk_service_client_impl.cc index 10dc82588..1c73c904c 100644 --- a/source/common/nighthawk_service_client_impl.cc +++ b/source/common/nighthawk_service_client_impl.cc @@ -12,9 +12,9 @@ NighthawkServiceClientImpl::PerformNighthawkBenchmark( nighthawk::client::ExecutionResponse response; *request.mutable_start_request()->mutable_options() = command_line_options; - ::grpc::ClientContext context; - std::shared_ptr<::grpc::ClientReaderWriterInterface> + grpc::ClientContext context; + std::shared_ptr> stream(nighthawk_service_stub->ExecutionStream(&context)); if (!stream->Write(request)) { @@ -32,7 +32,7 @@ NighthawkServiceClientImpl::PerformNighthawkBenchmark( if (!got_response) { return absl::InternalError("Nighthawk Service did not send a gRPC response."); } - ::grpc::Status status = stream->Finish(); + grpc::Status status = stream->Finish(); if (!status.ok()) { return absl::Status(static_cast(status.error_code()), status.error_message()); } diff --git a/source/sink/nighthawk_sink_client_impl.cc b/source/sink/nighthawk_sink_client_impl.cc index 8e3d7018c..8a643b4a6 100644 --- a/source/sink/nighthawk_sink_client_impl.cc +++ b/source/sink/nighthawk_sink_client_impl.cc @@ -8,16 +8,16 @@ absl::StatusOr NighthawkSinkClientImpl::StoreExecutionResponseStream( nighthawk::NighthawkSink::StubInterface& nighthawk_sink_stub, const nighthawk::StoreExecutionRequest& store_execution_request) const { - ::grpc::ClientContext context; - ::nighthawk::StoreExecutionResponse store_execution_response; - std::shared_ptr<::grpc::ClientWriterInterface<::nighthawk::StoreExecutionRequest>> stream( + grpc::ClientContext context; + nighthawk::StoreExecutionResponse store_execution_response; + std::shared_ptr> stream( nighthawk_sink_stub.StoreExecutionResponseStream(&context, &store_execution_response)); if (!stream->Write(store_execution_request)) { return absl::UnavailableError("Failed to write request to the Nighthawk Sink gRPC channel."); } else if (!stream->WritesDone()) { return absl::InternalError("WritesDone() failed on the Nighthawk Sink gRPC channel."); } - ::grpc::Status status = stream->Finish(); + grpc::Status status = stream->Finish(); if (!status.ok()) { return absl::Status(static_cast(status.error_code()), status.error_message()); } @@ -29,9 +29,9 @@ absl::StatusOr NighthawkSinkClientImpl::SinkRequestStre const nighthawk::SinkRequest& sink_request) const { nighthawk::SinkResponse response; - ::grpc::ClientContext context; + grpc::ClientContext context; std::shared_ptr< - ::grpc::ClientReaderWriterInterface> + grpc::ClientReaderWriterInterface> stream(nighthawk_sink_stub.SinkRequestStream(&context)); if (!stream->Write(sink_request)) { @@ -60,7 +60,7 @@ absl::StatusOr NighthawkSinkClientImpl::SinkRequestStre "Sink Service has started responding with more than one message."); got_response = true; } - ::grpc::Status status = stream->Finish(); + grpc::Status status = stream->Finish(); if (!status.ok()) { return absl::Status(static_cast(status.error_code()), status.error_message()); } diff --git a/source/sink/sink_impl.cc b/source/sink/sink_impl.cc index 900c3318b..ad15df326 100644 --- a/source/sink/sink_impl.cc +++ b/source/sink/sink_impl.cc @@ -39,7 +39,7 @@ absl::Status verifyCanBeUsedAsDirectoryName(absl::string_view s) { } // namespace absl::Status FileSinkImpl::StoreExecutionResultPiece( - const ::nighthawk::client::ExecutionResponse& response) const { + const nighthawk::client::ExecutionResponse& response) const { const std::string& execution_id = response.execution_id(); absl::Status status = verifyCanBeUsedAsDirectoryName(execution_id); if (!status.ok()) { @@ -72,7 +72,7 @@ absl::Status FileSinkImpl::StoreExecutionResultPiece( return absl::Status(); } -absl::StatusOr> +absl::StatusOr> FileSinkImpl::LoadExecutionResult(absl::string_view execution_id) const { absl::Status status = verifyCanBeUsedAsDirectoryName(execution_id); if (!status.ok()) { @@ -80,7 +80,7 @@ FileSinkImpl::LoadExecutionResult(absl::string_view execution_id) const { } std::filesystem::path filesystem_directory_path("/tmp/nh/" + std::string(execution_id) + "/"); - std::vector<::nighthawk::client::ExecutionResponse> responses; + std::vector responses; std::error_code error_code; for (const auto& it : @@ -88,7 +88,7 @@ FileSinkImpl::LoadExecutionResult(absl::string_view execution_id) const { if (error_code.value()) { break; } - ::nighthawk::client::ExecutionResponse response; + nighthawk::client::ExecutionResponse response; std::ifstream ifs(it.path(), std::ios_base::binary); if (!response.ParseFromIstream(&ifs)) { return absl::Status(absl::StatusCode::kInternal, diff --git a/source/sink/sink_impl.h b/source/sink/sink_impl.h index 59d53f908..7c3013b11 100644 --- a/source/sink/sink_impl.h +++ b/source/sink/sink_impl.h @@ -11,8 +11,8 @@ namespace Nighthawk { class FileSinkImpl : public Sink { public: absl::Status - StoreExecutionResultPiece(const ::nighthawk::client::ExecutionResponse& response) const override; - absl::StatusOr> + StoreExecutionResultPiece(const nighthawk::client::ExecutionResponse& response) const override; + absl::StatusOr> LoadExecutionResult(absl::string_view id) const override; }; diff --git a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc index bfbc39ad8..7b7ec0255 100644 --- a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc +++ b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc @@ -112,7 +112,7 @@ TEST(FakeMetricsPlugin, GetAllSupportedMetricNamesReturnsCorrectValues) { FakeMetricsPlugin metrics_plugin(config); EXPECT_THAT(metrics_plugin.GetAllSupportedMetricNames(), - ::testing::UnorderedElementsAre("metric1", "metric2")); + testing::UnorderedElementsAre("metric1", "metric2")); } TEST(MakeFakeMetricsPluginTypedExtensionConfig, SetsCorrectPluginName) { diff --git a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc index 905c9fa02..da9648a7f 100644 --- a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc +++ b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc @@ -64,7 +64,7 @@ TEST(FakeStepControllerConfigFactory, ValidateConfigWithBadConfigProtoReturnsErr } TEST(FakeStepControllerConfigFactory, ValidateConfigWithAritificialValidationErrorReturnsError) { - const int kExpectedStatusCode = ::grpc::DATA_LOSS; + const int kExpectedStatusCode = grpc::DATA_LOSS; const std::string kExpectedStatusMessage = "artificial validation error"; FakeStepControllerConfig config; config.mutable_artificial_validation_failure()->set_code(kExpectedStatusCode); @@ -113,7 +113,7 @@ TEST(FakeStepController, GetCurrentCommandLineOptionsReturnsRpsFromConfig) { TEST(FakeStepController, GetCurrentCommandLineOptionsReturnsArtificialErrorImmediately) { FakeStepControllerConfig config; - const int kExpectedCode = ::grpc::DEADLINE_EXCEEDED; + const int kExpectedCode = grpc::DEADLINE_EXCEEDED; const std::string kExpectedMessage = "artificial input setting error"; config.mutable_artificial_input_setting_failure()->set_code(kExpectedCode); config.mutable_artificial_input_setting_failure()->set_message(kExpectedMessage); @@ -129,7 +129,7 @@ TEST(FakeStepController, GetCurrentCommandLineOptionsReturnsArtificialErrorImmed TEST(FakeStepController, GetCurrentCommandLineOptionsReturnsArtificialErrorAfterCountdown) { FakeStepControllerConfig config; - const int kExpectedCode = ::grpc::DEADLINE_EXCEEDED; + const int kExpectedCode = grpc::DEADLINE_EXCEEDED; const std::string kExpectedMessage = "artificial input setting error"; config.mutable_artificial_input_setting_failure()->set_code(kExpectedCode); config.mutable_artificial_input_setting_failure()->set_message(kExpectedMessage); diff --git a/test/adaptive_load/metrics_plugin_test.cc b/test/adaptive_load/metrics_plugin_test.cc index 415099bd2..8f8bce002 100644 --- a/test/adaptive_load/metrics_plugin_test.cc +++ b/test/adaptive_load/metrics_plugin_test.cc @@ -13,7 +13,7 @@ namespace Nighthawk { namespace { class NighthawkStatsEmulatedMetricsPluginFixture - : public ::testing::TestWithParam> {}; + : public testing::TestWithParam> {}; TEST_P(NighthawkStatsEmulatedMetricsPluginFixture, ComputesCorrectMetric) { NighthawkStatsEmulatedMetricsPlugin plugin = @@ -35,17 +35,17 @@ TEST_P(NighthawkStatsEmulatedMetricsPluginFixture, ComputesCorrectMetric) { INSTANTIATE_TEST_SUITE_P( NighthawkStatsEmulatedMetricsPluginValuesTests, NighthawkStatsEmulatedMetricsPluginFixture, - ::testing::Values(std::make_tuple("achieved-rps", 256), - std::make_tuple("attempted-rps", 1024), - std::make_tuple("latency-ns-max", 600.0), - std::make_tuple("latency-ns-mean", 500.0), - std::make_tuple("latency-ns-mean-plus-1stdev", 511.0), - std::make_tuple("latency-ns-mean-plus-2stdev", 522.0), - std::make_tuple("latency-ns-mean-plus-3stdev", 533.0), - std::make_tuple("latency-ns-min", 400.0), - std::make_tuple("latency-ns-pstdev", 11.0), - std::make_tuple("send-rate", 0.25), - std::make_tuple("success-rate", 0.125))); + testing::Values(std::make_tuple("achieved-rps", 256), + std::make_tuple("attempted-rps", 1024), + std::make_tuple("latency-ns-max", 600.0), + std::make_tuple("latency-ns-mean", 500.0), + std::make_tuple("latency-ns-mean-plus-1stdev", 511.0), + std::make_tuple("latency-ns-mean-plus-2stdev", 522.0), + std::make_tuple("latency-ns-mean-plus-3stdev", 533.0), + std::make_tuple("latency-ns-min", 400.0), + std::make_tuple("latency-ns-pstdev", 11.0), + std::make_tuple("send-rate", 0.25), + std::make_tuple("success-rate", 0.125))); TEST(NighthawkStatsEmulatedMetricsPlugin, ReturnsErrorIfGlobalResultMissing) { nighthawk::client::Output empty_output; @@ -221,11 +221,11 @@ TEST(NighthawkStatsEmulatedMetricsPlugin, ReturnsCorrectSupportedMetricNames) { NighthawkStatsEmulatedMetricsPlugin plugin = NighthawkStatsEmulatedMetricsPlugin({}); std::vector supported_metrics = plugin.GetAllSupportedMetricNames(); EXPECT_THAT(supported_metrics, - ::testing::ElementsAre("achieved-rps", "attempted-rps", "latency-ns-max", - "latency-ns-mean", "latency-ns-mean-plus-1stdev", - "latency-ns-mean-plus-2stdev", "latency-ns-mean-plus-3stdev", - "latency-ns-min", "latency-ns-pstdev", "send-rate", - "success-rate")); + testing::ElementsAre("achieved-rps", "attempted-rps", "latency-ns-max", + "latency-ns-mean", "latency-ns-mean-plus-1stdev", + "latency-ns-mean-plus-2stdev", "latency-ns-mean-plus-3stdev", + "latency-ns-min", "latency-ns-pstdev", "send-rate", + "success-rate")); } } // namespace diff --git a/test/adaptive_load/plugin_loader_test.cc b/test/adaptive_load/plugin_loader_test.cc index 8f92e815d..c5622e008 100644 --- a/test/adaptive_load/plugin_loader_test.cc +++ b/test/adaptive_load/plugin_loader_test.cc @@ -22,6 +22,7 @@ namespace Nighthawk { namespace { using ::envoy::config::core::v3::TypedExtensionConfig; +using ::testing::HasSubstr; // A special value that causes ValidateConfig to return an error when included in the config // protos of the fake plugins in this file. @@ -243,7 +244,7 @@ TEST(PluginUtilTest, ReturnsErrorFromInputVariableSetterConfigValidator) { config.set_name("nighthawk.test-input-variable-setter"); *config.mutable_typed_config() = CreateTypedConfigAny(kBadConfigThreshold); EXPECT_THAT(LoadInputVariableSetterPlugin(config).status().message(), - ::testing::HasSubstr("input validation failed")); + HasSubstr("input validation failed")); } TEST(PluginUtilTest, PropagatesConfigProtoToInputVariableSetter) { @@ -261,7 +262,7 @@ TEST(PluginUtilTest, ReturnsErrorWhenInputVariableSetterPluginNotFound) { config.set_name("nonexistent-input-variable-setter"); *config.mutable_typed_config() = CreateTypedConfigAny(0.0); EXPECT_THAT(LoadInputVariableSetterPlugin(config).status().message(), - ::testing::HasSubstr("Didn't find a registered implementation")); + HasSubstr("Didn't find a registered implementation")); } TEST(PluginUtilTest, CreatesCorrectScoringFunctionType) { @@ -278,7 +279,7 @@ TEST(PluginUtilTest, ReturnsErrorFromScoringFunctionConfigValidator) { config.set_name("nighthawk.test-scoring-function"); *config.mutable_typed_config() = CreateTypedConfigAny(kBadConfigThreshold); EXPECT_THAT(LoadScoringFunctionPlugin(config).status().message(), - ::testing::HasSubstr("input validation failed")); + HasSubstr("input validation failed")); } TEST(PluginUtilTest, PropagatesConfigProtoToScoringFunction) { @@ -296,7 +297,7 @@ TEST(PluginUtilTest, ReturnsErrorWhenScoringFunctionPluginNotFound) { config.set_name("nonexistent-scoring-function"); *config.mutable_typed_config() = CreateTypedConfigAny(0.0); EXPECT_THAT(LoadScoringFunctionPlugin(config).status().message(), - ::testing::HasSubstr("Didn't find a registered implementation")); + HasSubstr("Didn't find a registered implementation")); } TEST(PluginUtilTest, CreatesCorrectMetricsPluginType) { @@ -312,8 +313,7 @@ TEST(PluginUtilTest, ReturnsErrorFromMetricsPluginConfigValidator) { TypedExtensionConfig config; config.set_name("nighthawk.test-metrics-plugin"); *config.mutable_typed_config() = CreateTypedConfigAny(kBadConfigThreshold); - EXPECT_THAT(LoadMetricsPlugin(config).status().message(), - ::testing::HasSubstr("input validation failed")); + EXPECT_THAT(LoadMetricsPlugin(config).status().message(), HasSubstr("input validation failed")); } TEST(PluginUtilTest, PropagatesConfigProtoToMetricsPlugin) { @@ -331,7 +331,7 @@ TEST(PluginUtilTest, ReturnsErrorWhenMetricsPluginNotFound) { config.set_name("nonexistent-metrics-plugin"); *config.mutable_typed_config() = CreateTypedConfigAny(0.0); EXPECT_THAT(LoadMetricsPlugin(config).status().message(), - ::testing::HasSubstr("Didn't find a registered implementation")); + HasSubstr("Didn't find a registered implementation")); } TEST(PluginUtilTest, CreatesCorrectStepControllerType) { @@ -350,7 +350,7 @@ TEST(PluginUtilTest, ReturnsErrorFromStepControllerConfigValidator) { *config.mutable_typed_config() = CreateTypedConfigAny(kBadConfigThreshold); nighthawk::client::CommandLineOptions options_template; EXPECT_THAT(LoadStepControllerPlugin(config, options_template).status().message(), - ::testing::HasSubstr("input validation failed")); + HasSubstr("input validation failed")); } TEST(PluginUtilTest, PropagatesConfigProtoToStepController) { @@ -382,7 +382,7 @@ TEST(PluginUtilTest, ReturnsErrorWhenStepControllerPluginNotFound) { *config.mutable_typed_config() = CreateTypedConfigAny(0.0); nighthawk::client::CommandLineOptions options_template; EXPECT_THAT(LoadStepControllerPlugin(config, options_template).status().message(), - ::testing::HasSubstr("Didn't find a registered implementation")); + HasSubstr("Didn't find a registered implementation")); } } // namespace diff --git a/test/adaptive_load/scoring_function_test.cc b/test/adaptive_load/scoring_function_test.cc index 495a48291..c5eeb3a01 100644 --- a/test/adaptive_load/scoring_function_test.cc +++ b/test/adaptive_load/scoring_function_test.cc @@ -119,7 +119,7 @@ MakeBinaryConfigWithBothThresholds(double lower_threshold, double upper_threshol } class BinaryScoringFunctionFixture - : public ::testing::TestWithParam< + : public testing::TestWithParam< std::tuple> {}; @@ -133,23 +133,22 @@ TEST_P(BinaryScoringFunctionFixture, ComputesCorrectScore) { INSTANTIATE_TEST_SUITE_P( BinaryScoringFunctionTest, BinaryScoringFunctionFixture, - ::testing::ValuesIn( - std::vector>{ - {MakeBinaryConfigWithUpperThreshold(5.0), 4.0, 1.0}, - {MakeBinaryConfigWithUpperThreshold(5.0), 5.0, 1.0}, - {MakeBinaryConfigWithUpperThreshold(5.0), 6.0, -1.0}, - - {MakeBinaryConfigWithLowerThreshold(5.0), 4.0, -1.0}, - {MakeBinaryConfigWithLowerThreshold(5.0), 5.0, 1.0}, - {MakeBinaryConfigWithLowerThreshold(5.0), 6.0, 1.0}, - - {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 6.0, 1.0}, - {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 5.0, 1.0}, - {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 7.0, 1.0}, - {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 4.0, -1.0}, - {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 8.0, -1.0}})); + testing::ValuesIn(std::vector>{ + {MakeBinaryConfigWithUpperThreshold(5.0), 4.0, 1.0}, + {MakeBinaryConfigWithUpperThreshold(5.0), 5.0, 1.0}, + {MakeBinaryConfigWithUpperThreshold(5.0), 6.0, -1.0}, + + {MakeBinaryConfigWithLowerThreshold(5.0), 4.0, -1.0}, + {MakeBinaryConfigWithLowerThreshold(5.0), 5.0, 1.0}, + {MakeBinaryConfigWithLowerThreshold(5.0), 6.0, 1.0}, + + {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 6.0, 1.0}, + {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 5.0, 1.0}, + {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 7.0, 1.0}, + {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 4.0, -1.0}, + {MakeBinaryConfigWithBothThresholds(5.0, 7.0), 8.0, -1.0}})); TEST(LinearScoringFunction, EvaluateMetricReturnsZeroForValueEqualToThreshold) { nighthawk::adaptive_load::LinearScoringFunctionConfig config; diff --git a/test/common/nighthawk_service_client_test.cc b/test/common/nighthawk_service_client_test.cc index f74e7d44f..ed3c0a34c 100644 --- a/test/common/nighthawk_service_client_test.cc +++ b/test/common/nighthawk_service_client_test.cc @@ -40,9 +40,9 @@ TEST(PerformNighthawkBenchmark, UsesSpecifiedCommandLineOptions) { EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); // Capture the Nighthawk request PerformNighthawkBenchmark sends on the channel. EXPECT_CALL(*mock_reader_writer, Write(_, _)) - .WillOnce(::testing::DoAll(::testing::SaveArg<0>(&request), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&request), Return(true))); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_reader_writer; }); @@ -71,7 +71,7 @@ TEST(PerformNighthawkBenchmark, ReturnsNighthawkResponseSuccessfully) { .WillOnce(Return(false)); EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_reader_writer; }); @@ -157,8 +157,7 @@ TEST(PerformNighthawkBenchmark, PropagatesErrorIfNighthawkServiceGrpcStreamClose EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, Finish()) - .WillOnce( - Return(::grpc::Status(::grpc::PERMISSION_DENIED, "Finish failure status message"))); + .WillOnce(Return(grpc::Status(grpc::PERMISSION_DENIED, "Finish failure status message"))); return mock_reader_writer; }); diff --git a/test/distributor/nighthawk_distributor_client_test.cc b/test/distributor/nighthawk_distributor_client_test.cc new file mode 100644 index 000000000..b26aa4d77 --- /dev/null +++ b/test/distributor/nighthawk_distributor_client_test.cc @@ -0,0 +1,187 @@ +#include "external/envoy/source/common/protobuf/protobuf.h" + +#include "api/client/options.pb.h" +#include "api/distributor/distributor.grpc.pb.h" +#include "api/distributor/distributor_mock.grpc.pb.h" + +#include "grpcpp/test/mock_stream.h" + +#include "distributor/nighthawk_distributor_client_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace Nighthawk { + +namespace { + +using DoAll; +using SaveArg; +using ::Envoy::Protobuf::util::MessageDifferencer; +using ::nighthawk::DistributedRequest; +using ::nighthawk::DistributedResponse; +using ::nighthawk::client::CommandLineOptions; +using ::testing::_; +using ::testing::HasSubstr; +using ::testing::Return; +using ::testing::SetArgPointee; + +TEST(DistributedRequest, UsesSpecifiedCommandLineOptions) { + const int kExpectedRps = 456; + DistributedRequest request; + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([&request](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + // DistributedRequest currently expects Read to return true exactly once. + EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); + // Capture the Nighthawk request DistributedRequest sends on the channel. + EXPECT_CALL(*mock_reader_writer, Write(_, _)) + .WillOnce(DoAll(SaveArg<0>(&request), Return(true))); + EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); + return mock_reader_writer; + }); + + DistributedRequest distributed_request; + nighthawk::client::ExecutionRequest execution_request; + nighthawk::client::StartRequest start_request; + CommandLineOptions command_line_options; + command_line_options.mutable_requests_per_second()->set_value(kExpectedRps); + *(start_request.mutable_options()) = command_line_options; + *(execution_request.mutable_start_request()) = start_request; + *(distributed_request.mutable_execution_request()) = execution_request; + NighthawkDistributorClientImpl client; + absl::StatusOr distributed_response_or = + client.DistributedRequest(mock_nighthawk_service_stub, distributed_request); + EXPECT_TRUE(distributed_response_or.ok()); + ASSERT_TRUE(request.has_execution_request()); + ASSERT_TRUE(request.execution_request().has_start_request()); + ASSERT_TRUE(request.execution_request().start_request().has_options()); + EXPECT_EQ(request.execution_request().start_request().options().requests_per_second().value(), + kExpectedRps); +} + +TEST(DistributedRequest, ReturnsNighthawkResponseSuccessfully) { + DistributedResponse expected_response; + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([&expected_response](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + // DistributedRequest currently expects Read to return true exactly once. + // Capture the gRPC response proto as it is written to the output parameter. + EXPECT_CALL(*mock_reader_writer, Read(_)) + .WillOnce(DoAll(SetArgPointee<0>(expected_response), Return(true))) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); + return mock_reader_writer; + }); + + NighthawkDistributorClientImpl client; + absl::StatusOr response_or = + client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); + EXPECT_TRUE(response_or.ok()); + DistributedResponse actual_response = response_or.value(); + EXPECT_TRUE(MessageDifferencer::Equivalent(actual_response, expected_response)); + EXPECT_EQ(actual_response.DebugString(), expected_response.DebugString()); +} + +TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceDoesNotSendResponse) { + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(false)); + EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); + return mock_reader_writer; + }); + + NighthawkDistributorClientImpl client; + absl::StatusOr response_or = + client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); + ASSERT_FALSE(response_or.ok()); + EXPECT_EQ(response_or.status().code(), absl::StatusCode::kInternal); + EXPECT_THAT(response_or.status().message(), + HasSubstr("Distributor Service did not send a gRPC response.")); +} + +TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceWriteFails) { + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(false)); + return mock_reader_writer; + }); + + NighthawkDistributorClientImpl client; + absl::StatusOr response_or = + client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); + ASSERT_FALSE(response_or.ok()); + EXPECT_EQ(response_or.status().code(), absl::StatusCode::kUnavailable); + EXPECT_THAT(response_or.status().message(), HasSubstr("Failed to write")); +} + +TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceWritesDoneFails) { + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(false)); + return mock_reader_writer; + }); + + NighthawkDistributorClientImpl client; + absl::StatusOr response_or = + client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); + ASSERT_FALSE(response_or.ok()); + EXPECT_EQ(response_or.status().code(), absl::StatusCode::kInternal); + EXPECT_THAT(response_or.status().message(), HasSubstr("WritesDone() failed")); +} + +TEST(DistributedRequest, PropagatesErrorIfNighthawkServiceGrpcStreamClosesAbnormally) { + nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; + // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under + // test requests a channel. Set call expectations on the inner mock channel. + EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) + .WillOnce([](grpc::ClientContext*) { + auto* mock_reader_writer = + new grpc::testing::MockClientReaderWriter(); + // DistributedRequest currently expects Read to return true exactly once. + EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); + EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); + EXPECT_CALL(*mock_reader_writer, Finish()) + .WillOnce( + Return(grpc::Status(grpc::PERMISSION_DENIED, "Finish failure status message"))); + return mock_reader_writer; + }); + + NighthawkDistributorClientImpl client; + absl::StatusOr response_or = + client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); + ASSERT_FALSE(response_or.ok()); + EXPECT_EQ(response_or.status().code(), absl::StatusCode::kPermissionDenied); + EXPECT_THAT(response_or.status().message(), HasSubstr("Finish failure status message")); +} + +} // namespace +} // namespace Nighthawk diff --git a/test/mocks/sink/mock_sink.h b/test/mocks/sink/mock_sink.h index 843cea183..3d57d6f14 100644 --- a/test/mocks/sink/mock_sink.h +++ b/test/mocks/sink/mock_sink.h @@ -10,10 +10,10 @@ class MockSink : public Sink { public: MockSink(); MOCK_CONST_METHOD1(StoreExecutionResultPiece, - absl::Status(const ::nighthawk::client::ExecutionResponse&)); + absl::Status(const nighthawk::client::ExecutionResponse&)); MOCK_CONST_METHOD1( LoadExecutionResult, - absl::StatusOr>(absl::string_view)); + absl::StatusOr>(absl::string_view)); }; } // namespace Nighthawk diff --git a/test/options_test.cc b/test/options_test.cc index a1f6c143b..0ace8c5df 100644 --- a/test/options_test.cc +++ b/test/options_test.cc @@ -354,7 +354,7 @@ std::vector RequestSourcePluginJsons() { } INSTANTIATE_TEST_SUITE_P(HappyPathRequestSourceConfigJsonSuccessfullyTranslatesIntoOptions, RequestSourcePluginTestFixture, - ::testing::ValuesIn(RequestSourcePluginJsons())); + testing::ValuesIn(RequestSourcePluginJsons())); // This test covers --RequestSourcePlugin, which can't be tested at the same time as --RequestSource // and some other options. This is the test for the inlineoptionslistplugin. diff --git a/test/server/http_filter_base_test.cc b/test/server/http_filter_base_test.cc index adf90896f..0a5ef3ceb 100644 --- a/test/server/http_filter_base_test.cc +++ b/test/server/http_filter_base_test.cc @@ -43,21 +43,21 @@ class HttpFilterBaseIntegrationTest INSTANTIATE_TEST_SUITE_P( IpVersions, HttpFilterBaseIntegrationTest, - ::testing::Combine(testing::ValuesIn(Envoy::TestEnvironment::getIpVersionsForTest()), - testing::ValuesIn({absl::string_view(R"EOF( + testing::Combine(testing::ValuesIn(Envoy::TestEnvironment::getIpVersionsForTest()), + testing::ValuesIn({absl::string_view(R"EOF( name: time-tracking typed_config: "@type": type.googleapis.com/nighthawk.server.ResponseOptions emit_previous_request_delta_in_response_header: "foo" )EOF"), - absl::string_view(R"EOF( + absl::string_view(R"EOF( name: dynamic-delay typed_config: "@type": type.googleapis.com/nighthawk.server.ResponseOptions static_delay: 0.1s )EOF"), - absl::string_view("name: test-server")}), - testing::ValuesIn({TestRequestMethod::GET, TestRequestMethod::POST}))); + absl::string_view("name: test-server")}), + testing::ValuesIn({TestRequestMethod::GET, TestRequestMethod::POST}))); TEST_P(HttpFilterBaseIntegrationTest, NoRequestLevelConfigurationShouldSucceed) { Envoy::IntegrationStreamDecoderPtr response = getResponse(getHappyFlowResponseOrigin()); diff --git a/test/service_test.cc b/test/service_test.cc index 57a78f64d..fd4ff39d8 100644 --- a/test/service_test.cc +++ b/test/service_test.cc @@ -100,7 +100,7 @@ class ServiceTest : public TestWithParam { ASSERT_FALSE(match_error.empty()); EXPECT_TRUE(response_.has_error_detail()); EXPECT_EQ(response_.has_output(), expect_output); - EXPECT_EQ(::grpc::StatusCode::INTERNAL, response_.error_detail().code()); + EXPECT_EQ(grpc::StatusCode::INTERNAL, response_.error_detail().code()); EXPECT_THAT(response_.error_detail().message(), HasSubstr(std::string(match_error))); EXPECT_TRUE(status.ok()); } @@ -143,7 +143,7 @@ INSTANTIATE_TEST_SUITE_P(IpVersions, ServiceTestWithParameterizedConstructor, TEST_P(ServiceTestWithParameterizedConstructor, ConstructorWithLoggingContextParameterCanRespondToRequests) { - std::unique_ptr<::grpc::ClientReaderWriter> stream = + std::unique_ptr> stream = stub_->ExecutionStream(&context_); stream->Write(request_, {}); stream->WritesDone(); @@ -152,7 +152,7 @@ TEST_P(ServiceTestWithParameterizedConstructor, EXPECT_THAT(response_.error_detail().message(), HasSubstr(std::string("Unknown failure"))); EXPECT_TRUE(response_.has_output()); EXPECT_GE(response_.output().results(0).counters().size(), 8); - ::grpc::Status status = stream->Finish(); + grpc::Status status = stream->Finish(); EXPECT_TRUE(status.ok()); } diff --git a/test/sink/nighthawk_sink_client_test.cc b/test/sink/nighthawk_sink_client_test.cc index 8a14f006a..3ed316c09 100644 --- a/test/sink/nighthawk_sink_client_test.cc +++ b/test/sink/nighthawk_sink_client_test.cc @@ -33,20 +33,20 @@ TEST(StoreExecutionResponseStream, UsesSpecifiedExecutionResponseArguments) { // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under // test requests a channel. Set call expectations on the inner mock channel. EXPECT_CALL(mock_nighthawk_sink_stub, StoreExecutionResponseStreamRaw) - .WillOnce([&observed_request_1](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([&observed_request_1](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)) - .WillOnce(::testing::DoAll(::testing::SaveArg<0>(&observed_request_1), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&observed_request_1), Return(true))); EXPECT_CALL(*mock_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_writer; }) - .WillOnce([&observed_request_2](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([&observed_request_2](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)) - .WillOnce(::testing::DoAll(::testing::SaveArg<0>(&observed_request_2), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&observed_request_2), Return(true))); EXPECT_CALL(*mock_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_writer; }); @@ -78,11 +78,11 @@ TEST(StoreExecutionResponseStream, ReturnsResponseSuccessfully) { // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under // test requests a channel. Set call expectations on the inner mock channel. EXPECT_CALL(mock_nighthawk_sink_stub, StoreExecutionResponseStreamRaw) - .WillOnce([](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_writer; }); @@ -97,7 +97,7 @@ TEST(StoreExecutionResponseStream, ReturnsErrorIfNighthawkServiceWriteFails) { // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under // test requests a channel. Set call expectations on the inner mock channel. EXPECT_CALL(mock_nighthawk_sink_stub, StoreExecutionResponseStreamRaw) - .WillOnce([](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)).WillOnce(Return(false)); return mock_writer; @@ -116,7 +116,7 @@ TEST(StoreExecutionResponseStream, ReturnsErrorIfNighthawkServiceWritesDoneFails // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under // test requests a channel. Set call expectations on the inner mock channel. EXPECT_CALL(mock_nighthawk_sink_stub, StoreExecutionResponseStreamRaw) - .WillOnce([](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_writer, WritesDone()).WillOnce(Return(false)); @@ -136,13 +136,13 @@ TEST(StoreExecutionResponseStream, PropagatesErrorIfNighthawkServiceGrpcStreamCl // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under // test requests a channel. Set call expectations on the inner mock channel. EXPECT_CALL(mock_nighthawk_sink_stub, StoreExecutionResponseStreamRaw) - .WillOnce([](grpc::ClientContext*, ::nighthawk::StoreExecutionResponse*) { + .WillOnce([](grpc::ClientContext*, nighthawk::StoreExecutionResponse*) { auto* mock_writer = new grpc::testing::MockClientWriter(); EXPECT_CALL(*mock_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_writer, WritesDone()).WillOnce(Return(true)); EXPECT_CALL(*mock_writer, Finish()) .WillOnce( - Return(::grpc::Status(::grpc::PERMISSION_DENIED, "Finish failure status message"))); + Return(grpc::Status(grpc::PERMISSION_DENIED, "Finish failure status message"))); return mock_writer; }); @@ -167,13 +167,13 @@ TEST(SinkRequest, UsesSpecifiedCommandLineOptions) { EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); // Capture the Nighthawk request SinkRequest sends on the channel. EXPECT_CALL(*mock_reader_writer, Write(_, _)) - .WillOnce(::testing::DoAll(::testing::SaveArg<0>(&request), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&request), Return(true))); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_reader_writer; }); - ::nighthawk::SinkRequest sink_request; + nighthawk::SinkRequest sink_request; *(sink_request.mutable_execution_id()) = "abc"; NighthawkSinkClientImpl client; absl::StatusOr distributed_response_or = @@ -198,13 +198,13 @@ TEST(SinkRequest, ReturnsNighthawkResponseSuccessfully) { .WillOnce(Return(false)); EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_reader_writer; }); NighthawkSinkClientImpl client; absl::StatusOr response_or = - client.SinkRequestStream(mock_nighthawk_sink_stub, ::nighthawk::SinkRequest()); + client.SinkRequestStream(mock_nighthawk_sink_stub, nighthawk::SinkRequest()); EXPECT_TRUE(response_or.ok()); SinkResponse actual_response = response_or.value(); EXPECT_TRUE(MessageDifferencer::Equivalent(actual_response, expected_response)); @@ -221,13 +221,13 @@ TEST(SinkRequest, WillFinishIfNighthawkServiceDoesNotSendResponse) { EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(false)); EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(::grpc::Status::OK)); + EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); return mock_reader_writer; }); NighthawkSinkClientImpl client; absl::StatusOr response_or = - client.SinkRequestStream(mock_nighthawk_sink_stub, ::nighthawk::SinkRequest()); + client.SinkRequestStream(mock_nighthawk_sink_stub, nighthawk::SinkRequest()); EXPECT_TRUE(response_or.ok()); } @@ -244,7 +244,7 @@ TEST(SinkRequest, ReturnsErrorIfNighthawkServiceWriteFails) { NighthawkSinkClientImpl client; absl::StatusOr response_or = - client.SinkRequestStream(mock_nighthawk_sink_stub, ::nighthawk::SinkRequest()); + client.SinkRequestStream(mock_nighthawk_sink_stub, nighthawk::SinkRequest()); ASSERT_FALSE(response_or.ok()); EXPECT_EQ(response_or.status().code(), absl::StatusCode::kUnavailable); EXPECT_THAT(response_or.status().message(), HasSubstr("Failed to write")); @@ -264,7 +264,7 @@ TEST(SinkRequest, ReturnsErrorIfNighthawkServiceWritesDoneFails) { NighthawkSinkClientImpl client; absl::StatusOr response_or = - client.SinkRequestStream(mock_nighthawk_sink_stub, ::nighthawk::SinkRequest()); + client.SinkRequestStream(mock_nighthawk_sink_stub, nighthawk::SinkRequest()); ASSERT_FALSE(response_or.ok()); EXPECT_EQ(response_or.status().code(), absl::StatusCode::kInternal); EXPECT_THAT(response_or.status().message(), HasSubstr("WritesDone() failed")); @@ -282,14 +282,13 @@ TEST(SinkRequest, PropagatesErrorIfNighthawkServiceGrpcStreamClosesAbnormally) { EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); EXPECT_CALL(*mock_reader_writer, Finish()) - .WillOnce( - Return(::grpc::Status(::grpc::PERMISSION_DENIED, "Finish failure status message"))); + .WillOnce(Return(grpc::Status(grpc::PERMISSION_DENIED, "Finish failure status message"))); return mock_reader_writer; }); NighthawkSinkClientImpl client; absl::StatusOr response_or = - client.SinkRequestStream(mock_nighthawk_sink_stub, ::nighthawk::SinkRequest()); + client.SinkRequestStream(mock_nighthawk_sink_stub, nighthawk::SinkRequest()); ASSERT_FALSE(response_or.ok()); EXPECT_EQ(response_or.status().code(), absl::StatusCode::kPermissionDenied); EXPECT_THAT(response_or.status().message(), HasSubstr("Finish failure status message")); diff --git a/test/sink/sink_test.cc b/test/sink/sink_test.cc index 1216a71da..df2169743 100644 --- a/test/sink/sink_test.cc +++ b/test/sink/sink_test.cc @@ -11,9 +11,9 @@ namespace Nighthawk { namespace { // Future sink implementations register here for testing top level generic sink behavior. -using SinkTypes = ::testing::Types; +using SinkTypes = testing::Types; -template class TypedSinkTest : public ::testing::Test { +template class TypedSinkTest : public testing::Test { public: void SetUp() override { uuid_ = random_.uuid(); } void TearDown() override { From 5003b27656ef015f39e442ef69829950e5a3596d Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Thu, 18 Mar 2021 22:32:13 +0100 Subject: [PATCH 2/2] Back out nighthawk_distributor_client_test.cc Signed-off-by: Otto van der Schaaf --- .../nighthawk_distributor_client_test.cc | 187 ------------------ 1 file changed, 187 deletions(-) delete mode 100644 test/distributor/nighthawk_distributor_client_test.cc diff --git a/test/distributor/nighthawk_distributor_client_test.cc b/test/distributor/nighthawk_distributor_client_test.cc deleted file mode 100644 index b26aa4d77..000000000 --- a/test/distributor/nighthawk_distributor_client_test.cc +++ /dev/null @@ -1,187 +0,0 @@ -#include "external/envoy/source/common/protobuf/protobuf.h" - -#include "api/client/options.pb.h" -#include "api/distributor/distributor.grpc.pb.h" -#include "api/distributor/distributor_mock.grpc.pb.h" - -#include "grpcpp/test/mock_stream.h" - -#include "distributor/nighthawk_distributor_client_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -namespace Nighthawk { - -namespace { - -using DoAll; -using SaveArg; -using ::Envoy::Protobuf::util::MessageDifferencer; -using ::nighthawk::DistributedRequest; -using ::nighthawk::DistributedResponse; -using ::nighthawk::client::CommandLineOptions; -using ::testing::_; -using ::testing::HasSubstr; -using ::testing::Return; -using ::testing::SetArgPointee; - -TEST(DistributedRequest, UsesSpecifiedCommandLineOptions) { - const int kExpectedRps = 456; - DistributedRequest request; - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([&request](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - // DistributedRequest currently expects Read to return true exactly once. - EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); - // Capture the Nighthawk request DistributedRequest sends on the channel. - EXPECT_CALL(*mock_reader_writer, Write(_, _)) - .WillOnce(DoAll(SaveArg<0>(&request), Return(true))); - EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); - return mock_reader_writer; - }); - - DistributedRequest distributed_request; - nighthawk::client::ExecutionRequest execution_request; - nighthawk::client::StartRequest start_request; - CommandLineOptions command_line_options; - command_line_options.mutable_requests_per_second()->set_value(kExpectedRps); - *(start_request.mutable_options()) = command_line_options; - *(execution_request.mutable_start_request()) = start_request; - *(distributed_request.mutable_execution_request()) = execution_request; - NighthawkDistributorClientImpl client; - absl::StatusOr distributed_response_or = - client.DistributedRequest(mock_nighthawk_service_stub, distributed_request); - EXPECT_TRUE(distributed_response_or.ok()); - ASSERT_TRUE(request.has_execution_request()); - ASSERT_TRUE(request.execution_request().has_start_request()); - ASSERT_TRUE(request.execution_request().start_request().has_options()); - EXPECT_EQ(request.execution_request().start_request().options().requests_per_second().value(), - kExpectedRps); -} - -TEST(DistributedRequest, ReturnsNighthawkResponseSuccessfully) { - DistributedResponse expected_response; - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([&expected_response](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - // DistributedRequest currently expects Read to return true exactly once. - // Capture the gRPC response proto as it is written to the output parameter. - EXPECT_CALL(*mock_reader_writer, Read(_)) - .WillOnce(DoAll(SetArgPointee<0>(expected_response), Return(true))) - .WillOnce(Return(false)); - EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()).WillOnce(Return(grpc::Status::OK)); - return mock_reader_writer; - }); - - NighthawkDistributorClientImpl client; - absl::StatusOr response_or = - client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); - EXPECT_TRUE(response_or.ok()); - DistributedResponse actual_response = response_or.value(); - EXPECT_TRUE(MessageDifferencer::Equivalent(actual_response, expected_response)); - EXPECT_EQ(actual_response.DebugString(), expected_response.DebugString()); -} - -TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceDoesNotSendResponse) { - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(false)); - EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - return mock_reader_writer; - }); - - NighthawkDistributorClientImpl client; - absl::StatusOr response_or = - client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); - ASSERT_FALSE(response_or.ok()); - EXPECT_EQ(response_or.status().code(), absl::StatusCode::kInternal); - EXPECT_THAT(response_or.status().message(), - HasSubstr("Distributor Service did not send a gRPC response.")); -} - -TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceWriteFails) { - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(false)); - return mock_reader_writer; - }); - - NighthawkDistributorClientImpl client; - absl::StatusOr response_or = - client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); - ASSERT_FALSE(response_or.ok()); - EXPECT_EQ(response_or.status().code(), absl::StatusCode::kUnavailable); - EXPECT_THAT(response_or.status().message(), HasSubstr("Failed to write")); -} - -TEST(DistributedRequest, ReturnsErrorIfNighthawkServiceWritesDoneFails) { - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(false)); - return mock_reader_writer; - }); - - NighthawkDistributorClientImpl client; - absl::StatusOr response_or = - client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); - ASSERT_FALSE(response_or.ok()); - EXPECT_EQ(response_or.status().code(), absl::StatusCode::kInternal); - EXPECT_THAT(response_or.status().message(), HasSubstr("WritesDone() failed")); -} - -TEST(DistributedRequest, PropagatesErrorIfNighthawkServiceGrpcStreamClosesAbnormally) { - nighthawk::MockNighthawkDistributorStub mock_nighthawk_service_stub; - // Configure the mock Nighthawk Service stub to return an inner mock channel when the code under - // test requests a channel. Set call expectations on the inner mock channel. - EXPECT_CALL(mock_nighthawk_service_stub, DistributedRequestStreamRaw) - .WillOnce([](grpc::ClientContext*) { - auto* mock_reader_writer = - new grpc::testing::MockClientReaderWriter(); - // DistributedRequest currently expects Read to return true exactly once. - EXPECT_CALL(*mock_reader_writer, Read(_)).WillOnce(Return(true)).WillOnce(Return(false)); - EXPECT_CALL(*mock_reader_writer, Write(_, _)).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, WritesDone()).WillOnce(Return(true)); - EXPECT_CALL(*mock_reader_writer, Finish()) - .WillOnce( - Return(grpc::Status(grpc::PERMISSION_DENIED, "Finish failure status message"))); - return mock_reader_writer; - }); - - NighthawkDistributorClientImpl client; - absl::StatusOr response_or = - client.DistributedRequest(mock_nighthawk_service_stub, nighthawk::DistributedRequest()); - ASSERT_FALSE(response_or.ok()); - EXPECT_EQ(response_or.status().code(), absl::StatusCode::kPermissionDenied); - EXPECT_THAT(response_or.status().message(), HasSubstr("Finish failure status message")); -} - -} // namespace -} // namespace Nighthawk