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

test: Break down huge monolith mock header to improve test compilation performance #11797

Merged
merged 17 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 257 additions & 19 deletions test/mocks/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,139 @@ 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/admin/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 = "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 +178,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 = ["mocks.cc"],
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",
],
)
1 change: 0 additions & 1 deletion test/mocks/server/admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,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
32 changes: 32 additions & 0 deletions test/mocks/server/admin_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <chrono>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we scripting the removal of extra #includes or doing it manually? We don't need most of these system headers in the new headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remove them manually, just forget to remove them. Thanks for pointing out

#include <cstdint>
#include <list>
#include <string>

#include "envoy/server/admin.h"

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

#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "spdlog/spdlog.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
27 changes: 27 additions & 0 deletions test/mocks/server/bootstrap_extension_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <chrono>
#include <cstdint>
#include <list>
#include <string>

#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