-
Notifications
You must be signed in to change notification settings - Fork 5.5k
test: Split huge monolith mock header to speed up test compilation #11649
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82ca456
Splitting monolith mock header to speed up test compilation
foreseeable a556a68
run formatter
foreseeable 21a3bff
fix the formatter issues
foreseeable 3779b37
Remove unsed using statements
foreseeable 2d9a460
Kick CI
foreseeable d3e2234
Reduce over-inclusion issues for divided headers
foreseeable fe69682
Removed unused deps in Bazel BUILD file
foreseeable 749457f
fix the test build dependencies
foreseeable c69b086
fix namespace aliases style issues
foreseeable 116417c
using fully qualified name
foreseeable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include "admin.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
| MockAdmin::MockAdmin() { | ||
| ON_CALL(*this, getConfigTracker()).WillByDefault(testing::ReturnRef(config_tracker_)); | ||
| } | ||
|
|
||
| MockAdmin::~MockAdmin() = default; | ||
|
|
||
| } // namespace Server | ||
|
|
||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/server/admin.h" | ||
|
|
||
| #include "absl/strings/string_view.h" | ||
| #include "config_tracker.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| using testing::NiceMock; | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
| class MockAdmin : public Admin { | ||
| public: | ||
| MockAdmin(); | ||
| ~MockAdmin() override; | ||
|
|
||
| // Server::Admin | ||
| MOCK_METHOD(bool, addHandler, | ||
| (const std::string& prefix, const std::string& help_text, HandlerCb callback, | ||
| bool removable, bool mutates_server_state)); | ||
| MOCK_METHOD(bool, removeHandler, (const std::string& prefix)); | ||
| MOCK_METHOD(Network::Socket&, socket, ()); | ||
| MOCK_METHOD(ConfigTracker&, getConfigTracker, ()); | ||
| MOCK_METHOD(void, startHttpListener, | ||
| (const std::string& access_log_path, const std::string& address_out_path, | ||
| Network::Address::InstanceConstSharedPtr address, | ||
| const Network::Socket::OptionsSharedPtr& socket_options, | ||
| Stats::ScopePtr&& listener_scope)); | ||
| MOCK_METHOD(Http::Code, request, | ||
| (absl::string_view path_and_query, absl::string_view method, | ||
| Http::ResponseHeaderMap& response_headers, std::string& body)); | ||
| MOCK_METHOD(void, addListenerToHandler, (Network::ConnectionHandler * handler)); | ||
|
|
||
| NiceMock<MockConfigTracker> config_tracker_; | ||
| }; | ||
| } // namespace Server | ||
|
|
||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "config_tracker.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using testing::_; | ||
|
Contributor
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. These should be moved to inside the innermost namespace, and they should be fully-qualified. See https://abseil.io/tips/119
Contributor
Author
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. fixed |
||
| using testing::Invoke; | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
| MockConfigTracker::MockConfigTracker() { | ||
| ON_CALL(*this, add_(_, _)) | ||
| .WillByDefault(Invoke([this](const std::string& key, Cb callback) -> EntryOwner* { | ||
| EXPECT_TRUE(config_tracker_callbacks_.find(key) == config_tracker_callbacks_.end()); | ||
| config_tracker_callbacks_[key] = callback; | ||
| return new MockEntryOwner(); | ||
| })); | ||
| } | ||
|
|
||
| MockConfigTracker::~MockConfigTracker() = default; | ||
|
|
||
| } // namespace Server | ||
|
|
||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/server/config_tracker.h" | ||
|
|
||
| #include "gmock/gmock.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
| class MockConfigTracker : public ConfigTracker { | ||
| public: | ||
| MockConfigTracker(); | ||
| ~MockConfigTracker() override; | ||
|
|
||
| struct MockEntryOwner : public EntryOwner {}; | ||
|
|
||
| MOCK_METHOD(EntryOwner*, add_, (std::string, Cb)); | ||
|
|
||
| // Server::ConfigTracker | ||
| MOCK_METHOD(const CbsMap&, getCallbacksMap, (), (const)); | ||
| EntryOwnerPtr add(const std::string& key, Cb callback) override { | ||
| return EntryOwnerPtr{add_(key, std::move(callback))}; | ||
| } | ||
|
|
||
| std::unordered_map<std::string, Cb> config_tracker_callbacks_; | ||
| }; | ||
| } // namespace Server | ||
|
|
||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using-declarations should only be used in .cc files. See https://google.github.io/styleguide/cppguide.html#Namespaces
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