-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adaptive load helper mocks #529
Changes from all commits
8ea442d
5ac755a
b8c25a5
1c19c68
7050686
0776563
16fd8f6
c383010
6e1a483
4ef1140
4111bf4
871a959
1fd77c1
edc36b2
4d0364e
aed6d94
d9ae87d
a05a6f5
8cd4d21
d814a96
5f5a885
7e20a78
9048267
306c0ec
d33f543
442cca9
677b783
cefb366
f3684df
5463051
46e0e25
f634642
3c39faa
b9c8f2b
5fc4db4
64e7852
12807f1
e8e960f
6306b4e
1ece783
70705e9
e576bc1
1fca528
ed32856
eecf00d
13179fb
3eb89e6
070c04d
1110cf2
fae60ad
12852c6
80578fa
50bc113
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load( | ||
"@envoy//bazel:envoy_build_system.bzl", | ||
"envoy_cc_mock", | ||
"envoy_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_cc_mock( | ||
name = "mock_metrics_evaluator", | ||
srcs = ["mock_metrics_evaluator.cc"], | ||
hdrs = ["mock_metrics_evaluator.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//include/nighthawk/adaptive_load:metrics_evaluator", | ||
], | ||
) | ||
|
||
envoy_cc_mock( | ||
name = "mock_session_spec_proto_helper", | ||
srcs = ["mock_session_spec_proto_helper.cc"], | ||
hdrs = ["mock_session_spec_proto_helper.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//include/nighthawk/adaptive_load:session_spec_proto_helper", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/adaptive_load/mock_metrics_evaluator.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockMetricsEvaluator::MockMetricsEvaluator() = default; | ||
|
||
} // namespace Nighthawk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/adaptive_load/metrics_evaluator.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock MetricsEvaluator that returns empty values from all methods. | ||
* | ||
* Typical usage: | ||
* | ||
* MockMetricsEvaluator mock_metrics_evaluator; | ||
* BenchmarkResult benchmark_result; | ||
* // (set benchmark_result fields here) | ||
* EXPECT_CALL(mock_metrics_evaluator, AnalyzeNighthawkBenchmark(_, _, _)) | ||
* .WillRepeatedly(Return(benchmark_result)); | ||
*/ | ||
class MockMetricsEvaluator : public MetricsEvaluator { | ||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockMetricsEvaluator(); | ||
|
||
MOCK_CONST_METHOD3(EvaluateMetric, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the difference between MOCK_CONST_METHOD3 and MOCK_CONST_METHOD1 just the number of arguments to the method being mocked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep |
||
absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation>( | ||
const nighthawk::adaptive_load::MetricSpec& metric_spec, | ||
MetricsPlugin& metrics_plugin, | ||
const nighthawk::adaptive_load::ThresholdSpec* threshold_spec)); | ||
|
||
MOCK_CONST_METHOD1(ExtractMetricSpecs, | ||
const std::vector<std::pair<const nighthawk::adaptive_load::MetricSpec*, | ||
const nighthawk::adaptive_load::ThresholdSpec*>>( | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec)); | ||
|
||
MOCK_CONST_METHOD3( | ||
AnalyzeNighthawkBenchmark, | ||
absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult>( | ||
const nighthawk::client::ExecutionResponse& execution_response, | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec, | ||
const absl::flat_hash_map<std::string, MetricsPluginPtr>& name_to_custom_plugin_map)); | ||
}; | ||
|
||
} // namespace Nighthawk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/adaptive_load/mock_session_spec_proto_helper.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockAdaptiveLoadSessionSpecProtoHelper::MockAdaptiveLoadSessionSpecProtoHelper() = default; | ||
|
||
} // namespace Nighthawk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/adaptive_load/session_spec_proto_helper.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock AdaptiveLoadSessionSpecProtoHelper that returns empty values or success from all methods | ||
* by default. | ||
* | ||
* In particular, SetSessionSpecDefaults does not pass its input value through to its output; | ||
* regardless of the output, it returns an empty proto, unless explicitly configured (see below). If | ||
* you don't need to inspect calls to the spec proto helper, it may be easier to use the real | ||
* AdaptiveLoadSessionSpecProtoHelperImpl in tests instead. | ||
* | ||
* Typical usage: | ||
* | ||
* NiceMock<MockAdaptiveLoadSessionSpecProtoHelper> mock_spec_proto_helper; | ||
* EXPECT_CALL(mock_spec_proto_helper, CheckSessionSpec(_)) | ||
* .WillOnce(Return(absl::OkStatus())); | ||
* AdaptiveLoadSessionSpec spec; | ||
* // Set spec fields here, including providing all defaults yourself. | ||
* EXPECT_CALL(mock_spec_proto_helper, SetSessionSpecDefaults(_)) | ||
* .WillOnce(Return(spec)); | ||
*/ | ||
class MockAdaptiveLoadSessionSpecProtoHelper : public AdaptiveLoadSessionSpecProtoHelper { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here - just a class-level comment explaining what this does / provide one example usage if that makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockAdaptiveLoadSessionSpecProtoHelper(); | ||
|
||
MOCK_CONST_METHOD1(SetSessionSpecDefaults, | ||
nighthawk::adaptive_load::AdaptiveLoadSessionSpec( | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec spec)); | ||
MOCK_CONST_METHOD1(CheckSessionSpec, | ||
absl::Status(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec)); | ||
}; | ||
|
||
} // namespace Nighthawk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/common/mock_nighthawk_service_client.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockNighthawkServiceClient::MockNighthawkServiceClient() = default; | ||
|
||
} // namespace Nighthawk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/common/nighthawk_service_client.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock NighthawkServiceClient that returns an empty response by default. | ||
* | ||
* Typical usage: | ||
* | ||
* NiceMock<MockNighthawkServiceClient> mock_nighthawk_service_client; | ||
* nighthawk::client::ExecutionResponse nighthawk_response; | ||
* EXPECT_CALL(mock_nighthawk_service_client, PerformNighthawkBenchmark(_, _)) | ||
* .WillRepeatedly(Return(nighthawk_response)); | ||
*/ | ||
class MockNighthawkServiceClient : public NighthawkServiceClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockNighthawkServiceClient(); | ||
|
||
MOCK_CONST_METHOD2(PerformNighthawkBenchmark, | ||
absl::StatusOr<nighthawk::client::ExecutionResponse>( | ||
nighthawk::client::NighthawkService::StubInterface* stub, | ||
const nighthawk::client::CommandLineOptions& options)); | ||
}; | ||
|
||
} // namespace Nighthawk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a description to this just clarifying that it's a MetricsEvaluator where all of the overloaded functions... are no-ops, I think? The name obviously goes a long way, but a short comment would help people know how to use it.
Maybe adding a couple lines of example usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful. Thank you