Skip to content
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

Merged
merged 53 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8ea442d
Merge pull request #5 from envoyproxy/master
eric846 Jun 1, 2020
5ac755a
Merge pull request #6 from envoyproxy/master
eric846 Jun 28, 2020
b8c25a5
Merge pull request #7 from envoyproxy/master
eric846 Jul 7, 2020
1c19c68
initial commit
eric846 Jul 9, 2020
7050686
fix comments
eric846 Jul 9, 2020
0776563
fix format
eric846 Jul 9, 2020
16fd8f6
rename adaptive_rps to adaptive_load
eric846 Jul 10, 2020
c383010
add field_selector in example
eric846 Jul 10, 2020
6e1a483
fix example comment
eric846 Jul 10, 2020
4ef1140
fix format
eric846 Jul 10, 2020
4111bf4
add support for fault injection headers
eric846 Jul 10, 2020
871a959
replace linear and binary search with exponential search
eric846 Jul 10, 2020
1fd77c1
add InputVariableSetter mechanism
eric846 Jul 11, 2020
edc36b2
add input variable setter to build file
eric846 Jul 11, 2020
4d0364e
fix syntax errors
eric846 Jul 11, 2020
aed6d94
rename samples/adaptive_rps
eric846 Jul 11, 2020
d9ae87d
improve comments, change step controller initial value from int64 to …
eric846 Jul 12, 2020
a05a6f5
add proto validation rules, fix comments, make rps the default input_…
eric846 Jul 13, 2020
8cd4d21
fix comment wording
eric846 Jul 13, 2020
d814a96
simplify protos, add defaults, specify required or optional
eric846 Jul 14, 2020
5f5a885
add missing newline
eric846 Jul 14, 2020
7e20a78
Kick CI
eric846 Jul 14, 2020
9048267
simplify protos
eric846 Jul 15, 2020
306c0ec
fix format
eric846 Jul 15, 2020
d33f543
fix some optional field comments and rules
eric846 Jul 15, 2020
442cca9
Merge pull request #10 from envoyproxy/master
eric846 Jul 16, 2020
677b783
add Nighthawk status field in BenchmarkResult as nested nighthawk.cli…
eric846 Jul 19, 2020
cefb366
switch to standard Envoy plugin config proto, add prefix to internal …
eric846 Jul 22, 2020
f3684df
Merge remote-tracking branch 'upstream/master' into adaptive-rps-protos2
eric846 Jul 22, 2020
5463051
create headers
eric846 Jul 22, 2020
46e0e25
fix format
eric846 Jul 22, 2020
f634642
use docstring format
eric846 Jul 22, 2020
3c39faa
fix typos in comments
eric846 Jul 23, 2020
b9c8f2b
split build target, get rid of ostream, change InputValueSetter to us…
eric846 Jul 24, 2020
5fc4db4
remove nested namespace, remove redundant _include in target names
eric846 Jul 26, 2020
64e7852
merge from upstream
eric846 Jul 29, 2020
12807f1
Merge remote-tracking branch 'upstream/master' into adaptive-rps-headers
eric846 Jul 29, 2020
e8e960f
merge from upstream
eric846 Aug 27, 2020
6306b4e
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 27, 2020
1ece783
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 28, 2020
70705e9
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 31, 2020
e576bc1
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 1, 2020
1fca528
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 3, 2020
ed32856
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 3, 2020
eecf00d
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 8, 2020
13179fb
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 10, 2020
3eb89e6
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 11, 2020
070c04d
add const to adaptive load helper interface methods, clean up deps an…
eric846 Sep 11, 2020
1110cf2
add mocks for adaptive load helpers
eric846 Sep 11, 2020
fae60ad
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 12, 2020
12852c6
Merge branch 'master2' into adaptive-rps-mocks
eric846 Sep 12, 2020
80578fa
fix typo
eric846 Sep 12, 2020
50bc113
add comments to mock classes
eric846 Sep 14, 2020
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
29 changes: 29 additions & 0 deletions test/mocks/adaptive_load/BUILD
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",
],
)
7 changes: 7 additions & 0 deletions test/mocks/adaptive_load/mock_metrics_evaluator.cc
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
46 changes: 46 additions & 0 deletions test/mocks/adaptive_load/mock_metrics_evaluator.h
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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super helpful. Thank you

public:
/**
* Empty constructor.
*/
MockMetricsEvaluator();

MOCK_CONST_METHOD3(EvaluateMetric,
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
7 changes: 7 additions & 0 deletions test/mocks/adaptive_load/mock_session_spec_proto_helper.cc
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
42 changes: 42 additions & 0 deletions test/mocks/adaptive_load/mock_session_spec_proto_helper.h
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
10 changes: 10 additions & 0 deletions test/mocks/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_mock(
name = "mock_nighthawk_service_client",
srcs = ["mock_nighthawk_service_client.cc"],
hdrs = ["mock_nighthawk_service_client.h"],
repository = "@envoy",
deps = [
"//include/nighthawk/common:nighthawk_service_client",
],
)

envoy_cc_mock(
name = "mock_rate_limiter",
srcs = ["mock_rate_limiter.cc"],
Expand Down
7 changes: 7 additions & 0 deletions test/mocks/common/mock_nighthawk_service_client.cc
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
32 changes: 32 additions & 0 deletions test/mocks/common/mock_nighthawk_service_client.h
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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