Skip to content

Commit

Permalink
test: Break down huge monolith mock header to improve test compilatio…
Browse files Browse the repository at this point in the history
…n performance (#11797)

Commit Message: breakdown `test/mocks/server/mocks.h` into different mock classes
Additional Description:  `test/mocks/server/mocks.h` is a wide-used mock header included by various test files. However it's very huge and most test files only used a small portion of it. Splitting it up into different mock classes will be helpful to reduce compilation time.

Risk Level: low
Testing: existing tests
Docs Changes: N/A
Release Notes: no
Related Issues: #10917

Signed-off-by: Muge Chen <mugechen@google.com>
  • Loading branch information
foreseeable authored Jul 6, 2020
1 parent 12c8c79 commit 7d5e12c
Show file tree
Hide file tree
Showing 50 changed files with 1,763 additions and 975 deletions.
275 changes: 256 additions & 19 deletions test/mocks/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,138 @@ envoy_cc_mock(
)

envoy_cc_mock(
name = "server_mocks",
srcs = ["mocks.cc"],
hdrs = ["mocks.h"],
name = "bootstrap_extension_factory_mocks",
srcs = ["bootstrap_extension_factory.cc"],
hdrs = ["bootstrap_extension_factory.h"],
deps = [
"//include/envoy/secret:secret_manager_interface",
"//include/envoy/server:admin_interface",
"//include/envoy/server:bootstrap_extension_config_interface",
"//include/envoy/server:configuration_interface",
],
)

envoy_cc_mock(
name = "options_mocks",
srcs = ["options.cc"],
hdrs = ["options.h"],
deps = [
"//include/envoy/server:options_interface",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
],
)

envoy_cc_mock(
name = "admin_stream_mocks",
srcs = ["admin_stream.cc"],
hdrs = ["admin_stream.h"],
deps = [
"//include/envoy/server:admin_interface",
"//test/mocks/http:http_mocks",
],
)

envoy_cc_mock(
name = "drain_manager_mocks",
srcs = ["drain_manager.cc"],
hdrs = ["drain_manager.h"],
deps = [
"//include/envoy/server:drain_manager_interface",
"//include/envoy/server:filter_config_interface",
],
)

envoy_cc_mock(
name = "watch_dog_mocks",
srcs = ["watch_dog.cc"],
hdrs = ["watch_dog.h"],
deps = [
"//include/envoy/server:watchdog_interface",
],
)

envoy_cc_mock(
name = "guard_dog_mocks",
srcs = ["guard_dog.cc"],
hdrs = ["guard_dog.h"],
deps = [
"//include/envoy/server:guarddog_interface",
"//include/envoy/server:health_checker_config_interface",
"//test/mocks/server:watch_dog_mocks",
],
)

envoy_cc_mock(
name = "hot_restart_mocks",
srcs = ["hot_restart.cc"],
hdrs = ["hot_restart.h"],
deps = [
"//include/envoy/server:instance_interface",
"//include/envoy/server:options_interface",
"//include/envoy/server:overload_manager_interface",
"//include/envoy/server:tracer_config_interface",
"//test/mocks/stats:stats_mocks",
],
)

envoy_cc_mock(
name = "listener_component_factory_mocks",
srcs = ["listener_component_factory.cc"],
hdrs = ["listener_component_factory.h"],
deps = [
"//include/envoy/server:drain_manager_interface",
"//include/envoy/server:listener_manager_interface",
"//test/mocks/network:network_mocks",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/listener/v3:pkg_cc_proto",
],
)

envoy_cc_mock(
name = "listener_manager_mocks",
srcs = ["listener_manager.cc"],
hdrs = ["listener_manager.h"],
deps = [
"//include/envoy/server:listener_manager_interface",
],
)

envoy_cc_mock(
name = "server_lifecycle_notifier_mocks",
srcs = ["server_lifecycle_notifier.cc"],
hdrs = ["server_lifecycle_notifier.h"],
deps = [
"//include/envoy/server:lifecycle_notifier_interface",
],
)

envoy_cc_mock(
name = "worker_factory_mocks",
srcs = ["worker_factory.cc"],
hdrs = ["worker_factory.h"],
deps = [
"//include/envoy/server:worker_interface",
"//include/envoy/ssl:context_manager_interface",
"//include/envoy/upstream:health_checker_interface",
"//test/mocks/server:worker_mocks",
],
)

envoy_cc_mock(
name = "worker_mocks",
srcs = ["worker.cc"],
hdrs = ["worker.h"],
deps = [
"//include/envoy/server:worker_interface",
],
)

envoy_cc_mock(
name = "overload_manager_mocks",
srcs = ["overload_manager.cc"],
hdrs = ["overload_manager.h"],
deps = [
"//include/envoy/server:overload_manager_interface",
],
)

envoy_cc_mock(
name = "instance_mocks",
srcs = ["instance.cc"],
hdrs = ["instance.h"],
deps = [
"//include/envoy/server:instance_interface",
"//source/common/grpc:context_lib",
"//source/common/http:context_lib",
"//source/common/secret:secret_manager_impl_lib",
Expand All @@ -64,14 +177,138 @@ envoy_cc_mock(
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/secret:secret_mocks",
"//test/mocks/server:admin_mocks",
"//test/mocks/server:config_tracker_mocks",
"//test/mocks/server:drain_manager_mocks",
"//test/mocks/server:hot_restart_mocks",
"//test/mocks/server:listener_manager_mocks",
"//test/mocks/server:options_mocks",
"//test/mocks/server:overload_manager_mocks",
"//test/mocks/server:server_lifecycle_notifier_mocks",
"//test/mocks/server:transport_socket_factory_context_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/mocks/tracing:tracing_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:test_time_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/listener/v3:pkg_cc_proto",
],
)

envoy_cc_mock(
name = "main_mocks",
srcs = ["main.cc"],
hdrs = ["main.h"],
deps = [
"//include/envoy/server:configuration_interface",
"//include/envoy/server:overload_manager_interface",
],
)

envoy_cc_mock(
name = "factory_context_mocks",
srcs = ["factory_context.cc"],
hdrs = ["factory_context.h"],
deps = [
"//test/mocks/server:drain_manager_mocks",
"//test/mocks/server:instance_mocks",
"//test/mocks/server:overload_manager_mocks",
"//test/mocks/server:server_lifecycle_notifier_mocks",
],
)

envoy_cc_mock(
name = "transport_socket_factory_context_mocks",
srcs = ["transport_socket_factory_context.cc"],
hdrs = ["transport_socket_factory_context.h"],
deps = [
"//include/envoy/server:tracer_config_interface",
"//source/common/secret:secret_manager_impl_lib",
"//test/mocks/api:api_mocks",
"//test/mocks/server:config_tracker_mocks",
"//test/mocks/upstream:upstream_mocks",
],
)

envoy_cc_mock(
name = "listener_factory_context_mocks",
srcs = ["listener_factory_context.cc"],
hdrs = ["listener_factory_context.h"],
deps = [
"//include/envoy/server:listener_manager_interface",
"//test/mocks/server:factory_context_mocks",
],
)

envoy_cc_mock(
name = "health_checker_factory_context_mocks",
srcs = ["health_checker_factory_context.cc"],
hdrs = ["health_checker_factory_context.h"],
deps = [
"//include/envoy/server:health_checker_config_interface",
"//test/mocks/api:api_mocks",
"//test/mocks/event:event_mocks",
"//test/mocks/protobuf:protobuf_mocks",
"//test/mocks/router:router_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/upstream:upstream_mocks",
],
)

envoy_cc_mock(
name = "filter_chain_factory_context_mocks",
srcs = ["filter_chain_factory_context.cc"],
hdrs = ["filter_chain_factory_context.h"],
deps = [
"//include/envoy/server:filter_config_interface",
"//test/mocks/server:factory_context_mocks",
],
)

envoy_cc_mock(
name = "tracer_factory_mocks",
srcs = ["tracer_factory.cc"],
hdrs = ["tracer_factory.h"],
deps = [
"//include/envoy/protobuf:message_validator_interface",
"//include/envoy/server:tracer_config_interface",
],
)

envoy_cc_mock(
name = "tracer_factory_context_mocks",
srcs = ["tracer_factory_context.cc"],
hdrs = ["tracer_factory_context.h"],
deps = [
"//include/envoy/server:configuration_interface",
"//test/mocks/server:instance_mocks",
"//test/mocks/server:tracer_factory_mocks",
],
)

envoy_cc_mock(
name = "server_mocks",
srcs = [],
hdrs = ["mocks.h"],
deps = [
"//test/mocks/server:admin_mocks",
"//test/mocks/server:admin_stream_mocks",
"//test/mocks/server:bootstrap_extension_factory_mocks",
"//test/mocks/server:config_tracker_mocks",
"//test/mocks/server:drain_manager_mocks",
"//test/mocks/server:factory_context_mocks",
"//test/mocks/server:filter_chain_factory_context_mocks",
"//test/mocks/server:guard_dog_mocks",
"//test/mocks/server:health_checker_factory_context_mocks",
"//test/mocks/server:hot_restart_mocks",
"//test/mocks/server:instance_mocks",
"//test/mocks/server:listener_component_factory_mocks",
"//test/mocks/server:listener_factory_context_mocks",
"//test/mocks/server:listener_manager_mocks",
"//test/mocks/server:main_mocks",
"//test/mocks/server:options_mocks",
"//test/mocks/server:overload_manager_mocks",
"//test/mocks/server:server_lifecycle_notifier_mocks",
"//test/mocks/server:tracer_factory_context_mocks",
"//test/mocks/server:tracer_factory_mocks",
"//test/mocks/server:transport_socket_factory_context_mocks",
"//test/mocks/server:watch_dog_mocks",
"//test/mocks/server:worker_factory_mocks",
"//test/mocks/server:worker_mocks",
],
)
3 changes: 0 additions & 3 deletions test/mocks/server/admin.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "admin.h"

#include <string>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -14,5 +12,4 @@ MockAdmin::MockAdmin() {
MockAdmin::~MockAdmin() = default;

} // namespace Server

} // namespace Envoy
1 change: 0 additions & 1 deletion test/mocks/server/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ class MockAdmin : public Admin {
::testing::NiceMock<MockConfigTracker> config_tracker_;
};
} // namespace Server

} // namespace Envoy
15 changes: 15 additions & 0 deletions test/mocks/server/admin_stream.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "admin_stream.h"

#include <string>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace Envoy {
namespace Server {
MockAdminStream::MockAdminStream() = default;

MockAdminStream::~MockAdminStream() = default;

} // namespace Server
} // namespace Envoy
25 changes: 25 additions & 0 deletions test/mocks/server/admin_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "envoy/server/admin.h"

#include "test/mocks/http/mocks.h"

#include "gmock/gmock.h"

namespace Envoy {
namespace Server {
class MockAdminStream : public AdminStream {
public:
MockAdminStream();
~MockAdminStream() override;

MOCK_METHOD(void, setEndStreamOnComplete, (bool));
MOCK_METHOD(void, addOnDestroyCallback, (std::function<void()>));
MOCK_METHOD(const Buffer::Instance*, getRequestBody, (), (const));
MOCK_METHOD(Http::RequestHeaderMap&, getRequestHeaders, (), (const));
MOCK_METHOD(NiceMock<Http::MockStreamDecoderFilterCallbacks>&, getDecoderFilterCallbacks, (),
(const));
MOCK_METHOD(Http::Http1StreamEncoderOptionsOptRef, http1StreamEncoderOptions, ());
};
} // namespace Server
} // namespace Envoy
12 changes: 12 additions & 0 deletions test/mocks/server/bootstrap_extension_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "bootstrap_extension_factory.h"

namespace Envoy {
namespace Server {
namespace Configuration {
MockBootstrapExtensionFactory::MockBootstrapExtensionFactory() = default;

MockBootstrapExtensionFactory::~MockBootstrapExtensionFactory() = default;

} // namespace Configuration
} // namespace Server
} // namespace Envoy
22 changes: 22 additions & 0 deletions test/mocks/server/bootstrap_extension_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "envoy/server/bootstrap_extension_config.h"

#include "gmock/gmock.h"

namespace Envoy {
namespace Server {
namespace Configuration {
class MockBootstrapExtensionFactory : public BootstrapExtensionFactory {
public:
MockBootstrapExtensionFactory();
~MockBootstrapExtensionFactory() override;

MOCK_METHOD(BootstrapExtensionPtr, createBootstrapExtension,
(const Protobuf::Message&, Configuration::ServerFactoryContext&), (override));
MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, (), (override));
MOCK_METHOD(std::string, name, (), (const, override));
};
} // namespace Configuration
} // namespace Server
} // namespace Envoy
Loading

0 comments on commit 7d5e12c

Please sign in to comment.