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

coverage: adding tests, bumping up #24351

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions source/extensions/clusters/common/logical_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ class LogicalHost : public HostImpl {
const envoy::config::endpoint::v3::LbEndpoint& lb_endpoint) {
const auto& health_check_config = lb_endpoint.endpoint().health_check_config();
auto health_check_address = resolveHealthCheckAddress(health_check_config, address);

absl::WriterMutexLock lock(&address_lock_);
setAddress(address);
setAddressList(address_list);
// TODO: the health checker only gets the first address in the list and
// will not walk the full happy eyeballs list. We should eventually fix
// this.
/* TODO: the health checker only gets the first address in the list and
* will not walk the full happy eyeballs list. We should eventually fix
* this. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change un-confuse the coverage checker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setHealthCheckAddress(health_check_address);
}

Expand Down
18 changes: 18 additions & 0 deletions test/extensions/clusters/common/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_test",
"envoy_package",
)

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_test(
name = "logical_host_test",
srcs = ["logical_host_test.cc"],
deps = [
"//source/extensions/clusters/common:logical_host_lib",
"//test/mocks/upstream:host_mocks",
],
)
47 changes: 47 additions & 0 deletions test/extensions/clusters/common/logical_host_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "source/extensions/clusters/common/logical_host.h"

#include "test/mocks/upstream/host.h"

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

using testing::_;
using testing::ReturnRef;

namespace Envoy {
namespace Extensions {
namespace Clusters {

class RealHostDescription : public testing::Test {
public:
Network::Address::InstanceConstSharedPtr address_ = nullptr;
Upstream::MockHost* mock_host_{new NiceMock<Upstream::MockHost>()};
Upstream::HostConstSharedPtr host_{mock_host_};
Upstream::RealHostDescription description_{address_, host_};
};

TEST_F(RealHostDescription, UnitTest) {
// No-op unit tests
description_.canary();
description_.metadata();
description_.priority();
EXPECT_EQ(nullptr, description_.healthCheckAddress());

// Pass through functions
EXPECT_CALL(*mock_host_, transportSocketFactory());
description_.transportSocketFactory();

EXPECT_CALL(*mock_host_, canCreateConnection(_));
description_.canCreateConnection(Upstream::ResourcePriority::Default);

EXPECT_CALL(*mock_host_, loadMetricStats());
description_.loadMetricStats();

std::vector<Network::Address::InstanceConstSharedPtr> address_list;
EXPECT_CALL(*mock_host_, addressList()).WillOnce(ReturnRef(address_list));
description_.addressList();
}

} // namespace Clusters
} // namespace Extensions
} // namespace Envoy
1 change: 0 additions & 1 deletion test/per_file_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ declare -a KNOWN_LOW_COVERAGE=(
"source/common/watchdog:58.6" # Death tests don't report LCOV
"source/exe:92.6"
"source/extensions/access_loggers/wasm:93.5"
"source/extensions/clusters/common:68.2"
"source/extensions/common:92.9"
"source/extensions/common/tap:92.9"
"source/extensions/common/wasm:87.5" # flaky: be careful adjusting
Expand Down