Skip to content

Commit

Permalink
Address review comment for unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Yiming Jin <[email protected]>
  • Loading branch information
GinYM committed May 15, 2021
1 parent 2373b0a commit 9b10394
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ envoy_cc_test_library(
"//source/extensions/filters/http/health_check:config",
"//test/common/http/http2:http2_frame",
"//test/integration/filters:continue_after_local_reply_filter_lib",
"//test/integration/filters:continue_after_local_reply_filter_with_metadata_lib",
"//test/integration/filters:continue_headers_only_inject_body",
"//test/integration/filters:encoder_decoder_buffer_filter_lib",
"//test/integration/filters:invalid_header_filter_lib",
"//test/integration/filters:local_reply_during_encoding_data_filter_lib",
"//test/integration/filters:local_reply_during_encoding_filter_lib",
"//test/integration/filters:local_reply_with_metadata_filter_lib",
"//test/integration/filters:random_pause_filter_lib",
"//test/test_common:logging_lib",
"//test/test_common:utility_lib",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/filters/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ envoy_cc_test_library(
)

envoy_cc_test_library(
name = "continue_after_local_reply_filter_with_metadata_lib",
name = "local_reply_with_metadata_filter_lib",
srcs = [
"continue_after_local_reply_with_metadata_filter.cc",
"local_reply_with_metadata_filter.cc",
],
deps = [
":common_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@

namespace Envoy {

// A filter that calls Http::FilterHeadersStatus::Continue and set metadata after a local reply.
class ContinueAfterLocalReplyWithMetadataFilter : public Http::PassThroughFilter {
// A filter that calls Http::FilterHeadersStatus::StopAll and set metadata after a local reply.
class LocalReplyWithMetadataFilter : public Http::PassThroughFilter {
public:
constexpr static char name[] = "continue-after-local-reply-with-metadata-filter";
constexpr static char name[] = "local-reply-with-metadata-filter";

Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap&, bool) override {
Http::MetadataMap metadata_map = {{"headers", "headers"}, {"duplicate", "duplicate"}};
Http::MetadataMapPtr metadata_map_ptr = std::make_unique<Http::MetadataMap>(metadata_map);
decoder_callbacks_->addDecodedMetadata().emplace_back(std::move(metadata_map_ptr));
decoder_callbacks_->sendLocalReply(Envoy::Http::Code::OK, "", nullptr, absl::nullopt,
"ContinueAfterLocalReplyFilter is ready");
return Http::FilterHeadersStatus::Continue;
"LocalReplyWithMetadataFilter is ready");
return Http::FilterHeadersStatus::StopIteration;
}

// Adds new metadata to metadata_map directly
Http::FilterMetadataStatus decodeMetadata(Http::MetadataMap& metadata_map) override {
metadata_map["data"] = "data";
throw EnvoyException("Should not call decode metadata after local reply.");
ASSERT(false);
return Http::FilterMetadataStatus::Continue;
}
};

constexpr char ContinueAfterLocalReplyWithMetadataFilter::name[];
static Registry::RegisterFactory<SimpleFilterConfig<ContinueAfterLocalReplyWithMetadataFilter>,
constexpr char LocalReplyWithMetadataFilter::name[];
static Registry::RegisterFactory<SimpleFilterConfig<LocalReplyWithMetadataFilter>,
Server::Configuration::NamedHttpFilterConfigFactory>
register_;

Expand Down
19 changes: 6 additions & 13 deletions test/integration/protocol_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2316,27 +2316,20 @@ TEST_P(DownstreamProtocolIntegrationTest, HeaderNormalizationRejection) {

// Tests a filter that returns a FilterHeadersStatus::Continue after a local reply without
// processing new metadata generated in decodeHeader
TEST_P(DownstreamProtocolIntegrationTest, ContinueAfterLocalReplyWithMetadata) {
TEST_P(DownstreamProtocolIntegrationTest, LocalReplyWithMetadata) {
config_helper_.addFilter(R"EOF(
name: continue-after-local-reply-with-metadata-filter
name: local-reply-with-metadata-filter
typed_config:
"@type": type.googleapis.com/google.protobuf.Empty
)EOF");
initialize();

codec_client_ = makeHttpConnection(lookupPort("http"));
// Send a headers only request.
IntegrationStreamDecoderPtr response;
EXPECT_ENVOY_BUG(
{
response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
ASSERT_TRUE(response->complete());
ASSERT_EQ("200", response->headers().getStatusValue());
ENVOY_LOG(info, "test upstream request");
},
"envoy bug failure: !continue_iteration || !state_.local_complete_. "
"Details: Filter did not return StopAll or StopIteration after sending a local reply.");
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
ASSERT_TRUE(response->complete());
ASSERT_EQ("200", response->headers().getStatusValue());
}

} // namespace Envoy

0 comments on commit 9b10394

Please sign in to comment.