Skip to content

Commit

Permalink
adding integration tests for listener filter matcher
Browse files Browse the repository at this point in the history
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
  • Loading branch information
yanjunxiang-google committed May 30, 2022
1 parent 79679db commit 2864e0b
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions test/integration/listener_extension_discovery_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace Envoy {
namespace {

enum class ListenerMatcherType { NULLMATCHER, ANYMATCHER, NOTANYMATCHER };

class ListenerExtensionDiscoveryIntegrationTest : public Grpc::GrpcClientIntegrationParamTest,
public BaseIntegrationTest {
public:
Expand All @@ -21,8 +23,10 @@ class ListenerExtensionDiscoveryIntegrationTest : public Grpc::GrpcClientIntegra
data_("HelloWorld"), port_name_("http") {}

void addDynamicFilter(const std::string& name, bool apply_without_warming,
bool set_default_config = true, bool rate_limit = false) {
bool set_default_config = true, bool rate_limit = false,
ListenerMatcherType matcher = ListenerMatcherType::NULLMATCHER) {
config_helper_.addConfigModifier([name, apply_without_warming, set_default_config, rate_limit,
matcher,
this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
listener->set_stat_prefix("listener_stat");
Expand All @@ -48,6 +52,12 @@ class ListenerExtensionDiscoveryIntegrationTest : public Grpc::GrpcClientIntegra
if (rate_limit) {
api_config_source->mutable_rate_limit_settings()->mutable_max_tokens()->set_value(10);
}
// Add listener filter matcher config.
if (matcher == ListenerMatcherType::ANYMATCHER) {
listener_filter->mutable_filter_disabled()->set_any_match(true);
} else if (matcher == ListenerMatcherType::NOTANYMATCHER) {
listener_filter->mutable_filter_disabled()->mutable_not_match()->set_any_match(true);
}
auto* grpc_service = api_config_source->add_grpc_services();
setGrpcService(*grpc_service, "ecds_cluster", getEcdsFakeUpstream().localAddress());
});
Expand Down Expand Up @@ -195,6 +205,36 @@ TEST_P(ListenerExtensionDiscoveryIntegrationTest, BasicSuccess) {
sendDataVerifyResults(3);
}

TEST_P(ListenerExtensionDiscoveryIntegrationTest, BasicSuccessWithAnyMatcher) {
on_server_init_function_ = [&]() { waitXdsStream(); };
// Add dynamic filter with any matcher, which effectively disables the filter.
addDynamicFilter(filter_name_, false, true, false, ListenerMatcherType::ANYMATCHER);
initialize();
EXPECT_EQ(test_server_->server().initManager().state(), Init::Manager::State::Initializing);

// Send config update to have listener filter drain 5 bytes of data.
sendXdsResponse(filter_name_, "1", 5);
test_server_->waitForCounterGe(
"extension_config_discovery.tcp_listener_filter." + filter_name_ + ".config_reload", 1);
// Send data, verify the listener filter doesn't drain any data.
sendDataVerifyResults(0);
}

TEST_P(ListenerExtensionDiscoveryIntegrationTest, BasicSuccessWithNotAnyMatcher) {
on_server_init_function_ = [&]() { waitXdsStream(); };
// Not any matcher negates the any matcher, which effectively enable the filter.
addDynamicFilter(filter_name_, false, true, false, ListenerMatcherType::NOTANYMATCHER);
initialize();
EXPECT_EQ(test_server_->server().initManager().state(), Init::Manager::State::Initializing);

// Send config update to have listener filter drain 5 bytes of data.
sendXdsResponse(filter_name_, "1", 5);
test_server_->waitForCounterGe(
"extension_config_discovery.tcp_listener_filter." + filter_name_ + ".config_reload", 1);
// Send data, verify the listener filter drains five bytes data.
sendDataVerifyResults(5);
}

TEST_P(ListenerExtensionDiscoveryIntegrationTest, BasicSuccessWithTtl) {
on_server_init_function_ = [&]() { waitXdsStream(); };
addDynamicFilter(filter_name_, false, false);
Expand Down Expand Up @@ -346,7 +386,6 @@ TEST_P(ListenerExtensionDiscoveryIntegrationTest, TwoDynamicTwoStaticFilterMixed
addDynamicFilter(filter_name_, true);
addStaticFilter("foobar", 2);
initialize();

EXPECT_EQ(test_server_->server().initManager().state(), Init::Manager::State::Initializing);

sendXdsResponse(filter_name_, "1", 3);
Expand All @@ -363,7 +402,6 @@ TEST_P(ListenerExtensionDiscoveryIntegrationTest, TwoDynamicTwoStaticFilterMixed
addDynamicFilter(filter_name_, true);
addDynamicFilter(filter_name_, false);
initialize();

EXPECT_EQ(test_server_->server().initManager().state(), Init::Manager::State::Initializing);

sendXdsResponse(filter_name_, "1", 2);
Expand All @@ -373,6 +411,23 @@ TEST_P(ListenerExtensionDiscoveryIntegrationTest, TwoDynamicTwoStaticFilterMixed
sendDataVerifyResults(8);
}

TEST_P(ListenerExtensionDiscoveryIntegrationTest, DynamicStaticFilterMixedWithAnyMatcher) {
on_server_init_function_ = [&]() { waitXdsStream(); };
addStaticFilter("bar", 2);
addStaticFilter("baz", 2);
addDynamicFilter(filter_name_, true);
// This filter with any matcher is effectively disabled.
addDynamicFilter(filter_name_, false, true, false, ListenerMatcherType::ANYMATCHER);
initialize();
EXPECT_EQ(test_server_->server().initManager().state(), Init::Manager::State::Initializing);

sendXdsResponse(filter_name_, "1", 3);
test_server_->waitForCounterGe(
"extension_config_discovery.tcp_listener_filter." + filter_name_ + ".config_reload", 1);
// The filters totally drain 2 + 2 + 3 bytes.
sendDataVerifyResults(7);
}

TEST_P(ListenerExtensionDiscoveryIntegrationTest, DestroyDuringInit) {
// If rate limiting is enabled on the config source, gRPC mux drainage updates the requests
// queue size on destruction. The update calls out to stats scope nested under the extension
Expand Down

0 comments on commit 2864e0b

Please sign in to comment.