forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Split huge monolith mock header to speed up test compilation (e…
…nvoyproxy#11649) Commit Message: Split huge monolith mock header to speed up test compilation Additional Description: `cluster_manager_test` only used a simple mock class `MockAdmin` from `test/mocks/server/mocks.h`, which is a huge mock library. After splitting, the overall build time for `cluster_manager_test` reduced from 143.481s to 82.443s in my build cluster. Risk Level: low Testing: existing tests Docs Changes: N/A Release Notes: no Related Issues: envoyproxy#10917 Signed-off-by: Muge Chen <mugechen@google.com> Signed-off-by: yashwant121 <yadavyashwant36@gmail.com>
- Loading branch information
1 parent
56c1342
commit fae4a4e
Showing
9 changed files
with
140 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 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,39 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/server/admin.h" | ||
|
||
#include "absl/strings/string_view.h" | ||
#include "config_tracker.h" | ||
#include "gmock/gmock.h" | ||
|
||
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)); | ||
|
||
::testing::NiceMock<MockConfigTracker> config_tracker_; | ||
}; | ||
} // namespace Server | ||
|
||
} // namespace Envoy |
This file contains 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" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
|
||
using ::testing::_; | ||
using ::testing::Invoke; | ||
|
||
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 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 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 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 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 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