test/extensions/filters/http/ext_proc/filter_test.cc
TEST_F(HttpFilterTest, PostAndIgnoreFailure) {
  initialize(R"EOF(
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  failure_mode_allow: true
  )EOF");

  EXPECT_TRUE(config_->failureModeAllow());

  // Create synthetic HTTP request
  HttpTestUtility::addDefaultHeaders(request_headers_, "POST");
  EXPECT_EQ(FilterHeadersStatus::StopAllIterationAndWatermark,
            filter_->decodeHeaders(request_headers_, false));
  EXPECT_FALSE(stream_close_sent_);

  // Oh no! The remote server had a failure which we will ignore
  EXPECT_CALL(decoder_callbacks_, continueDecoding());
  stream_callbacks_->onGrpcError(Grpc::Status::Internal);

  data_.add("foo");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_));

  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encode100ContinueHeaders(response_headers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, true));
  data_.add("bar");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, false));
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_));
  filter_->onDestroy();
  // The other side closed the stream
  EXPECT_FALSE(stream_close_sent_);

  EXPECT_EQ(1, config_->stats().streams_started_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_sent_.value());
  EXPECT_EQ(1, config_->stats().streams_closed_.value());
  EXPECT_EQ(1, config_->stats().failure_mode_allowed_.value());
}
// Using the default configuration, test the filter with a processor that
// returns an error from the gRPC stream that is ignored because the
// failure_mode_allow parameter is set.
Using the default configuration, test the filter with a processor that
returns an error from the gRPC stream that is ignored because the
failure_mode_allow parameter is set.
Using the default configuration test the filter with a processor that returns an error from the gRPC stream that is ignored because the failure_mode_allow parameter is set .
TEST_F(HttpFilterTest, PostAndIgnoreFailure) {
  initialize(R"EOF(
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  failure_mode_allow: true
  )EOF");
  EXPECT_TRUE(config_->failureModeAllow());
  HttpTestUtility::addDefaultHeaders(request_headers_, "POST");
  EXPECT_EQ(FilterHeadersStatus::StopAllIterationAndWatermark,
            filter_->decodeHeaders(request_headers_, false));
  EXPECT_FALSE(stream_close_sent_);
  EXPECT_CALL(decoder_callbacks_, continueDecoding());
  stream_callbacks_->onGrpcError(Grpc::Status::Internal);
  data_.add("foo");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encode100ContinueHeaders(response_headers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, true));
  data_.add("bar");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, false));
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_));
  filter_->onDestroy();
  EXPECT_FALSE(stream_close_sent_);
  EXPECT_EQ(1, config_->stats().streams_started_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_sent_.value());
  EXPECT_EQ(1, config_->stats().streams_closed_.value());
  EXPECT_EQ(1, config_->stats().failure_mode_allowed_.value());
}
TEST_F ( HttpFilterTest , PostAndIgnoreFailure ) { initialize ( R" EOF ( 
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  failure_mode_allow: true
   ) EOF " ) ; EXPECT_TRUE ( config_ -> failureModeAllow ( ) ) ; HttpTestUtility :: addDefaultHeaders ( request_headers_ , " " ) ; EXPECT_EQ ( FilterHeadersStatus :: StopAllIterationAndWatermark , filter_ -> decodeHeaders ( request_headers_ , false ) ) ; EXPECT_FALSE ( stream_close_sent_ ) ; EXPECT_CALL ( decoder_callbacks_ , continueDecoding ( ) ) ; stream_callbacks_ -> onGrpcError ( Grpc :: Status :: Internal ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> decodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> decodeTrailers ( request_trailers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encode100ContinueHeaders ( response_headers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encodeHeaders ( response_headers_ , true ) ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , false ) ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> encodeTrailers ( response_trailers_ ) ) ; filter_ -> onDestroy ( ) ; EXPECT_FALSE ( stream_close_sent_ ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_started_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . stream_msgs_sent_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_closed_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . failure_mode_allowed_ . value ( ) ) ; }
Using the default configuration, test the filter with a processor that
returns an error from the gRPC stream that is ignored because the
failure_mode_allow parameter is set.
Using the default configuration test the filter with a processor that returns an error from the gRPC stream that is ignored because the failure_mode_allow parameter is set .
// Create synthetic HTTP request // Oh no! The remote server had a failure which we will ignore // The other side closed the stream