diff --git a/test/integration/grpc_json_transcoder_integration_test.cc b/test/integration/grpc_json_transcoder_integration_test.cc index e3a2ab08530f..f83d76d17c93 100644 --- a/test/integration/grpc_json_transcoder_integration_test.cc +++ b/test/integration/grpc_json_transcoder_integration_test.cc @@ -47,29 +47,26 @@ class GrpcJsonTranscoderIntegrationTest const std::vector& grpc_response_messages, const Status& grpc_status, Http::HeaderMap&& response_headers, const std::string& response_body) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request_stream; + response_.reset(new IntegrationStreamDecoder(*dispatcher_)); - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); if (!request_body.empty()) { - Http::StreamEncoder& encoder = codec_client->startRequest(request_headers, *response); + request_encoder_ = &codec_client_->startRequest(request_headers, *response_); Buffer::OwnedImpl body(request_body); - codec_client->sendData(encoder, body, true); + codec_client_->sendData(*request_encoder_, body, true); } else { - codec_client->makeHeaderOnlyRequest(request_headers, *response); + codec_client_->makeHeaderOnlyRequest(request_headers, *response_); } - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); - request_stream = fake_upstream_connection->waitForNewStream(); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + upstream_request_ = fake_upstream_connection_->waitForNewStream(); if (!grpc_request_messages.empty()) { - request_stream->waitForEndStream(*dispatcher_); + upstream_request_->waitForEndStream(*dispatcher_); Grpc::Decoder grpc_decoder; std::vector frames; - EXPECT_TRUE(grpc_decoder.decode(request_stream->body(), frames)); + EXPECT_TRUE(grpc_decoder.decode(upstream_request_->body(), frames)); EXPECT_EQ(grpc_request_messages.size(), frames.size()); for (size_t i = 0; i < grpc_request_messages.size(); ++i) { @@ -90,41 +87,41 @@ class GrpcJsonTranscoderIntegrationTest if (grpc_response_messages.empty()) { response_headers.insertGrpcStatus().value(grpc_status.error_code()); response_headers.insertGrpcMessage().value(grpc_status.error_message()); - request_stream->encodeHeaders(response_headers, true); + upstream_request_->encodeHeaders(response_headers, true); } else { - request_stream->encodeHeaders(response_headers, false); + upstream_request_->encodeHeaders(response_headers, false); for (const auto& response_message_str : grpc_response_messages) { ResponseType response_message; EXPECT_TRUE(TextFormat::ParseFromString(response_message_str, &response_message)); auto buffer = Grpc::Common::serializeBody(response_message); - request_stream->encodeData(*buffer, false); + upstream_request_->encodeData(*buffer, false); } Http::TestHeaderMapImpl response_trailers; response_trailers.insertGrpcStatus().value(grpc_status.error_code()); response_trailers.insertGrpcMessage().value(grpc_status.error_message()); - request_stream->encodeTrailers(response_trailers); + upstream_request_->encodeTrailers(response_trailers); } - EXPECT_TRUE(request_stream->complete()); + EXPECT_TRUE(upstream_request_->complete()); } else { - request_stream->waitForReset(); + upstream_request_->waitForReset(); } - response->waitForEndStream(); - EXPECT_TRUE(response->complete()); + response_->waitForEndStream(); + EXPECT_TRUE(response_->complete()); response_headers.iterate( [](const Http::HeaderEntry& entry, void* context) -> void { IntegrationStreamDecoder* response = static_cast(context); Http::LowerCaseString lower_key{entry.key().c_str()}; EXPECT_STREQ(entry.value().c_str(), response->headers().get(lower_key)->value().c_str()); }, - response.get()); + response_.get()); if (!response_body.empty()) { - EXPECT_EQ(response_body, response->body()); + EXPECT_EQ(response_body, response_->body()); } - codec_client->close(); - fake_upstream_connection->close(); - fake_upstream_connection->waitForDisconnect(); + codec_client_->close(); + fake_upstream_connection_->close(); + fake_upstream_connection_->waitForDisconnect(); } }; diff --git a/test/integration/http2_integration_test.cc b/test/integration/http2_integration_test.cc index 9f7e1f6503d6..0ab1ef72fa74 100644 --- a/test/integration/http2_integration_test.cc +++ b/test/integration/http2_integration_test.cc @@ -122,15 +122,12 @@ TEST_P(Http2IntegrationTest, MaxHeadersInCodec) { big_headers.addCopy("big", std::string(63 * 1024, 'a')); - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - Http::StreamEncoder* downstream_request{}; executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); }, - [&]() -> void { downstream_request = &codec_client->startRequest(big_headers, *response); }, - [&]() -> void { response->waitForReset(); }, [&]() -> void { codec_client->close(); }}); + [&]() -> void { codec_client_->startRequest(big_headers, *response_); }, + [&]() -> void { response_->waitForReset(); }, [&]() -> void { codec_client_->close(); }}); } TEST_P(Http2IntegrationTest, DownstreamResetBeforeResponseComplete) { @@ -166,26 +163,25 @@ TEST_P(Http2IntegrationTest, BadFrame) { } TEST_P(Http2IntegrationTest, GoAway) { - IntegrationCodecClientPtr codec_client; - Http::StreamEncoder* encoder; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - executeActions( - {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); - }, - [&]() -> void { - encoder = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/healthcheck"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); - }, - [&]() -> void { codec_client->goAway(); }, - [&]() -> void { codec_client->sendData(*encoder, 0, true); }, - [&]() -> void { response->waitForEndStream(); }, [&]() -> void { codec_client->close(); }}); - - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + executeActions({[&]() -> void { + codec_client_ = + makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); + }, + [&]() -> void { + request_encoder_ = &codec_client_->startRequest( + Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/healthcheck"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); + }, + [&]() -> void { codec_client_->goAway(); }, + [&]() -> void { codec_client_->sendData(*request_encoder_, 0, true); }, + [&]() -> void { response_->waitForEndStream(); }, + [&]() -> void { codec_client_->close(); }}); + + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); } TEST_P(Http2IntegrationTest, Trailers) { testTrailers(1024, 2048); } @@ -194,7 +190,6 @@ TEST_P(Http2IntegrationTest, TrailersGiantBody) { testTrailers(1024 * 1024, 1024 void Http2IntegrationTest::simultaneousRequest(uint32_t port, int32_t request1_bytes, int32_t request2_bytes) { - IntegrationCodecClientPtr codec_client; FakeHttpConnectionPtr fake_upstream_connection1; FakeHttpConnectionPtr fake_upstream_connection2; Http::StreamEncoder* encoder1; @@ -204,14 +199,15 @@ void Http2IntegrationTest::simultaneousRequest(uint32_t port, int32_t request1_b FakeStreamPtr upstream_request1; FakeStreamPtr upstream_request2; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, + {[&]() -> void { codec_client_ = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, // Start request 1 [&]() -> void { - encoder1 = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response1); + encoder1 = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response1); }, [&]() -> void { fake_upstream_connection1 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); @@ -221,11 +217,12 @@ void Http2IntegrationTest::simultaneousRequest(uint32_t port, int32_t request1_b // Start request 2 [&]() -> void { response2.reset(new IntegrationStreamDecoder(*dispatcher_)); - encoder2 = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response2); + encoder2 = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response2); }, [&]() -> void { fake_upstream_connection2 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); @@ -234,14 +231,14 @@ void Http2IntegrationTest::simultaneousRequest(uint32_t port, int32_t request1_b // Finish request 1 [&]() -> void { - codec_client->sendData(*encoder1, request1_bytes, true); + codec_client_->sendData(*encoder1, request1_bytes, true); }, [&]() -> void { upstream_request1->waitForEndStream(*dispatcher_); }, // Finish request 2 [&]() -> void { - codec_client->sendData(*encoder2, request2_bytes, true); + codec_client_->sendData(*encoder2, request2_bytes, true); }, [&]() -> void { upstream_request2->waitForEndStream(*dispatcher_); }, @@ -277,7 +274,7 @@ void Http2IntegrationTest::simultaneousRequest(uint32_t port, int32_t request1_b }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, + [&]() -> void { codec_client_->close(); }, [&]() -> void { fake_upstream_connection1->close(); }, [&]() -> void { fake_upstream_connection1->waitForDisconnect(); }, [&]() -> void { fake_upstream_connection2->close(); }, diff --git a/test/integration/http2_upstream_integration_test.cc b/test/integration/http2_upstream_integration_test.cc index ad8ecfe1ad0a..3ae5b9443a50 100644 --- a/test/integration/http2_upstream_integration_test.cc +++ b/test/integration/http2_upstream_integration_test.cc @@ -104,59 +104,56 @@ TEST_P(Http2UpstreamIntegrationTest, DownstreamResetBeforeResponseComplete) { TEST_P(Http2UpstreamIntegrationTest, Trailers) { testTrailers(1024, 2048); } void Http2UpstreamIntegrationTest::bidirectionalStreaming(uint32_t port, uint32_t bytes) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - Http::StreamEncoder* encoder; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr upstream_request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, + {[&]() -> void { codec_client_ = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, // Start request [&]() -> void { - encoder = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + request_encoder_ = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request = fake_upstream_connection->waitForNewStream(); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, // Send some data [&]() -> void { - codec_client->sendData(*encoder, bytes, false); + codec_client_->sendData(*request_encoder_, bytes, false); }, - [&]() -> void { upstream_request->waitForData(*dispatcher_, bytes); }, + [&]() -> void { upstream_request_->waitForData(*dispatcher_, bytes); }, // Start response [&]() -> void { - upstream_request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - upstream_request->encodeData(bytes, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(bytes, false); }, - [&]() -> void { response->waitForBodyData(bytes); }, + [&]() -> void { response_->waitForBodyData(bytes); }, // Finish request [&]() -> void { - codec_client->sendTrailers(*encoder, Http::TestHeaderMapImpl{{"trailer", "foo"}}); + codec_client_->sendTrailers(*request_encoder_, + Http::TestHeaderMapImpl{{"trailer", "foo"}}); }, - [&]() -> void { upstream_request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, // Finish response [&]() -> void { - upstream_request->encodeTrailers(Http::TestHeaderMapImpl{{"trailer", "bar"}}); + upstream_request_->encodeTrailers(Http::TestHeaderMapImpl{{"trailer", "bar"}}); }, - [&]() -> void { response->waitForEndStream(); }, + [&]() -> void { response_->waitForEndStream(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); + EXPECT_TRUE(response_->complete()); } TEST_P(Http2UpstreamIntegrationTest, BidirectionalStreaming) { @@ -168,67 +165,62 @@ TEST_P(Http2UpstreamIntegrationTest, LargeBidirectionalStreamingWithBufferLimits } TEST_P(Http2UpstreamIntegrationTest, BidirectionalStreamingReset) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - Http::StreamEncoder* encoder; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr upstream_request; executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); }, // Start request [&]() -> void { - encoder = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + request_encoder_ = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request = fake_upstream_connection->waitForNewStream(); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, // Send some data [&]() -> void { - codec_client->sendData(*encoder, 1024, false); + codec_client_->sendData(*request_encoder_, 1024, false); }, - [&]() -> void { upstream_request->waitForData(*dispatcher_, 1024); }, + [&]() -> void { upstream_request_->waitForData(*dispatcher_, 1024); }, // Start response [&]() -> void { - upstream_request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - upstream_request->encodeData(1024, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(1024, false); }, - [&]() -> void { response->waitForBodyData(1024); }, + [&]() -> void { response_->waitForBodyData(1024); }, // Finish request [&]() -> void { - codec_client->sendTrailers(*encoder, Http::TestHeaderMapImpl{{"trailer", "foo"}}); + codec_client_->sendTrailers(*request_encoder_, + Http::TestHeaderMapImpl{{"trailer", "foo"}}); }, - [&]() -> void { upstream_request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, // Reset - [&]() -> void { upstream_request->encodeResetStream(); }, - [&]() -> void { response->waitForReset(); }, + [&]() -> void { upstream_request_->encodeResetStream(); }, + [&]() -> void { response_->waitForReset(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); - EXPECT_FALSE(response->complete()); + EXPECT_FALSE(response_->complete()); } void Http2UpstreamIntegrationTest::simultaneousRequest(uint32_t port, uint32_t request1_bytes, uint32_t request2_bytes, uint32_t response1_bytes, uint32_t response2_bytes) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; Http::StreamEncoder* encoder1; Http::StreamEncoder* encoder2; IntegrationStreamDecoderPtr response1(new IntegrationStreamDecoder(*dispatcher_)); @@ -236,40 +228,42 @@ void Http2UpstreamIntegrationTest::simultaneousRequest(uint32_t port, uint32_t r FakeStreamPtr upstream_request1; FakeStreamPtr upstream_request2; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, + {[&]() -> void { codec_client_ = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, // Start request 1 [&]() -> void { - encoder1 = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response1); + encoder1 = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response1); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request1 = fake_upstream_connection->waitForNewStream(); }, + [&]() -> void { upstream_request1 = fake_upstream_connection_->waitForNewStream(); }, // Start request 2 [&]() -> void { - encoder2 = &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response2); + encoder2 = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response2); }, - [&]() -> void { upstream_request2 = fake_upstream_connection->waitForNewStream(); }, + [&]() -> void { upstream_request2 = fake_upstream_connection_->waitForNewStream(); }, // Finish request 1 [&]() -> void { - codec_client->sendData(*encoder1, request1_bytes, true); + codec_client_->sendData(*encoder1, request1_bytes, true); }, [&]() -> void { upstream_request1->waitForEndStream(*dispatcher_); }, // Finish request 2 [&]() -> void { - codec_client->sendData(*encoder2, request2_bytes, true); + codec_client_->sendData(*encoder2, request2_bytes, true); }, [&]() -> void { upstream_request2->waitForEndStream(*dispatcher_); }, @@ -305,9 +299,9 @@ void Http2UpstreamIntegrationTest::simultaneousRequest(uint32_t port, uint32_t r }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } TEST_P(Http2UpstreamIntegrationTest, SimultaneousRequest) { @@ -323,30 +317,28 @@ void Http2UpstreamIntegrationTest::manySimultaneousRequests(uint32_t port, uint3 uint32_t) { TestRandomGenerator rand; const uint32_t num_requests = 50; - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; std::vector encoders; std::vector responses; std::vector upstream_requests; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, + {[&]() -> void { codec_client_ = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, [&]() -> void { for (uint32_t i = 0; i < num_requests; ++i) { responses.push_back( IntegrationStreamDecoderPtr{new IntegrationStreamDecoder(*dispatcher_)}); encoders.push_back( - &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *responses[i])); - codec_client->sendData(*encoders[i], request_bytes, true); + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *responses[i])); + codec_client_->sendData(*encoders[i], request_bytes, true); } }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); for (uint32_t i = 0; i < num_requests; ++i) { - upstream_requests.push_back(fake_upstream_connection->waitForNewStream()); + upstream_requests.push_back(fake_upstream_connection_->waitForNewStream()); } }, [&]() -> void { @@ -375,9 +367,9 @@ void Http2UpstreamIntegrationTest::manySimultaneousRequests(uint32_t port, uint3 }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } TEST_P(Http2UpstreamIntegrationTest, ManySimultaneousRequest) { @@ -392,35 +384,33 @@ TEST_P(Http2UpstreamIntegrationTest, UpstreamConnectionCloseWithManyStreams) { uint32_t port = lookupPort("http_with_buffer_limits"); TestRandomGenerator rand; const uint32_t num_requests = rand.random() % 50 + 1; - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; std::vector encoders; std::vector responses; std::vector upstream_requests; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, + {[&]() -> void { codec_client_ = makeHttpConnection(port, Http::CodecClient::Type::HTTP2); }, [&]() -> void { for (uint32_t i = 0; i < num_requests; ++i) { responses.push_back( IntegrationStreamDecoderPtr{new IntegrationStreamDecoder(*dispatcher_)}); encoders.push_back( - &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *responses[i])); + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *responses[i])); // Reset a few streams to test how reset and watermark interact. if (i % 15 == 0) { - codec_client->sendReset(*encoders[i]); + codec_client_->sendReset(*encoders[i]); } else { - codec_client->sendData(*encoders[i], 0, true); + codec_client_->sendData(*encoders[i], 0, true); } } }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); for (uint32_t i = 0; i < num_requests; ++i) { - upstream_requests.push_back(fake_upstream_connection->waitForNewStream()); + upstream_requests.push_back(fake_upstream_connection_->waitForNewStream()); } for (uint32_t i = 0; i < num_requests; ++i) { if (i % 15 != 0) { @@ -431,7 +421,7 @@ TEST_P(Http2UpstreamIntegrationTest, UpstreamConnectionCloseWithManyStreams) { } } // Close the connection. - fake_upstream_connection->close(); + fake_upstream_connection_->close(); }, [&]() -> void { // Ensure the streams are all reset successfully. @@ -443,8 +433,8 @@ TEST_P(Http2UpstreamIntegrationTest, UpstreamConnectionCloseWithManyStreams) { }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } } // namespace Envoy diff --git a/test/integration/integration.cc b/test/integration/integration.cc index d8fc95e3b247..60b4dd26d6dd 100644 --- a/test/integration/integration.cc +++ b/test/integration/integration.cc @@ -363,12 +363,8 @@ void BaseIntegrationTest::testRouterRequestAndResponseWithBody(Network::ClientCo uint64_t request_size, uint64_t response_size, bool big_header) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + {[&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { Http::TestHeaderMapImpl headers{ {":method", "POST"}, {":path", "/test/long/url"}, {":scheme", "http"}, @@ -377,59 +373,55 @@ void BaseIntegrationTest::testRouterRequestAndResponseWithBody(Network::ClientCo headers.addCopy("big", std::string(4096, 'a')); } - codec_client->makeRequestWithBody(headers, request_size, *response); + codec_client_->makeRequestWithBody(headers, request_size, *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(response_size, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(response_size, true); }, - [&]() -> void { response->waitForEndStream(); }, + [&]() -> void { response_->waitForEndStream(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(request_size, request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(request_size, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(response_size, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(response_size, response_->body().size()); } void BaseIntegrationTest::testRouterHeaderOnlyRequestAndResponse( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type, bool close_upstream) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + {[&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}, - {"x-lyft-user-id", "123"}}, - *response); + codec_client_->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}, + {"x-lyft-user-id", "123"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); }, - [&]() -> void { response->waitForEndStream(); }, + [&]() -> void { response_->waitForEndStream(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }}); + [&]() -> void { codec_client_->close(); }}); // The following allows us to test shutting down the server with active connection pool // connections. Either way we need to clean up the upstream connections to avoid race conditions. @@ -437,15 +429,15 @@ void BaseIntegrationTest::testRouterHeaderOnlyRequestAndResponse( test_server_.reset(); } - fake_upstream_connection->close(); - fake_upstream_connection->waitForDisconnect(); + fake_upstream_connection_->close(); + fake_upstream_connection_->waitForDisconnect(); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(0U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(0U, response_->body().size()); } void BaseIntegrationTest::testRouterNotFound(Http::CodecClient::Type type) { @@ -474,24 +466,22 @@ void BaseIntegrationTest::testRouterRedirect(Http::CodecClient::Type type) { void BaseIntegrationTest::testDrainClose(Http::CodecClient::Type type) { test_server_->drainManager().draining_ = true; - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - executeActions({[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + executeActions({[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest( + codec_client_->makeHeaderOnlyRequest( Http::TestHeaderMapImpl{{":method", "GET"}, {":path", "/healthcheck"}, {":scheme", "http"}, {":authority", "host"}}, - *response); + *response_); }, - [&]() -> void { response->waitForEndStream(); }, - [&]() -> void { codec_client->waitForDisconnect(); }}); + [&]() -> void { response_->waitForEndStream(); }, + [&]() -> void { codec_client_->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); if (type == Http::CodecClient::Type::HTTP2) { - EXPECT_TRUE(codec_client->sawGoAway()); + EXPECT_TRUE(codec_client_->sawGoAway()); } test_server_->drainManager().draining_ = false; @@ -499,401 +489,368 @@ void BaseIntegrationTest::testDrainClose(Http::CodecClient::Type type) { void BaseIntegrationTest::testRouterUpstreamDisconnectBeforeRequestComplete( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; std::list> actions = { - [&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + [&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForHeadersComplete(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }, - [&]() -> void { response->waitForEndStream(); }}; + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForHeadersComplete(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }, + [&]() -> void { response_->waitForEndStream(); }}; if (type == Http::CodecClient::Type::HTTP1) { - actions.push_back([&]() -> void { codec_client->waitForDisconnect(); }); + actions.push_back([&]() -> void { codec_client_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { codec_client->close(); }); + actions.push_back([&]() -> void { codec_client_->close(); }); } executeActions(actions); - EXPECT_FALSE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_FALSE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); - EXPECT_EQ("upstream connect error or disconnect/reset before headers", response->body()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("503", response_->headers().Status()->value().c_str()); + EXPECT_EQ("upstream connect error or disconnect/reset before headers", response_->body()); } void BaseIntegrationTest::testRouterUpstreamDisconnectBeforeResponseComplete( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; std::list> actions = { - [&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + [&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + codec_client_->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}; + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}; if (type == Http::CodecClient::Type::HTTP1) { - actions.push_back([&]() -> void { codec_client->waitForDisconnect(); }); + actions.push_back([&]() -> void { codec_client_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { response->waitForReset(); }); - actions.push_back([&]() -> void { codec_client->close(); }); + actions.push_back([&]() -> void { response_->waitForReset(); }); + actions.push_back([&]() -> void { codec_client_->close(); }); } executeActions(actions); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(0U, response->body().size()); + EXPECT_FALSE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(0U, response_->body().size()); } void BaseIntegrationTest::testRouterDownstreamDisconnectBeforeRequestComplete( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; std::list> actions = { - [&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + [&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForHeadersComplete(); }, - [&]() -> void { codec_client->close(); }}; + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForHeadersComplete(); }, + [&]() -> void { codec_client_->close(); }}; if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { request->waitForReset(); }); - actions.push_back([&]() -> void { fake_upstream_connection->close(); }); - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { upstream_request_->waitForReset(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->close(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } executeActions(actions); - EXPECT_FALSE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_FALSE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_FALSE(response->complete()); + EXPECT_FALSE(response_->complete()); } void BaseIntegrationTest::testRouterDownstreamDisconnectBeforeResponseComplete( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; std::list> actions = { - [&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + [&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + codec_client_->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(512, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, false); }, - [&]() -> void { response->waitForBodyData(512); }, - [&]() -> void { codec_client->close(); }}; + [&]() -> void { response_->waitForBodyData(512); }, + [&]() -> void { codec_client_->close(); }}; if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { request->waitForReset(); }); - actions.push_back([&]() -> void { fake_upstream_connection->close(); }); - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { upstream_request_->waitForReset(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->close(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } executeActions(actions); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_FALSE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); } void BaseIntegrationTest::testRouterUpstreamResponseBeforeRequestComplete( Network::ClientConnectionPtr&& conn, Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; std::list> actions = { - [&]() -> void { codec_client = makeHttpConnection(std::move(conn), type); }, + [&]() -> void { codec_client_ = makeHttpConnection(std::move(conn), type); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForHeadersComplete(); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForHeadersComplete(); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(512, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, true); }, - [&]() -> void { response->waitForEndStream(); }}; + [&]() -> void { response_->waitForEndStream(); }}; if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { request->waitForReset(); }); - actions.push_back([&]() -> void { fake_upstream_connection->close(); }); - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { upstream_request_->waitForReset(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->close(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } if (type == Http::CodecClient::Type::HTTP1) { - actions.push_back([&]() -> void { codec_client->waitForDisconnect(); }); + actions.push_back([&]() -> void { codec_client_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { codec_client->close(); }); + actions.push_back([&]() -> void { codec_client_->close(); }); } executeActions(actions); - EXPECT_FALSE(request->complete()); - EXPECT_EQ(0U, request->bodyLength()); + EXPECT_FALSE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); } void BaseIntegrationTest::testRetry(Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + {[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { - codec_client->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}, - {"x-forwarded-for", "10.0.0.1"}, - {"x-envoy-retry-on", "5xx"}}, - 1024, *response); + codec_client_->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}, + {"x-forwarded-for", "10.0.0.1"}, + {"x-envoy-retry-on", "5xx"}}, + 1024, *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "503"}}, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "503"}}, false); }, [&]() -> void { if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - fake_upstream_connection->waitForDisconnect(); - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_->waitForDisconnect(); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); } else { - request->waitForReset(); + upstream_request_->waitForReset(); } }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(512, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, true); }, [&]() -> void { - response->waitForEndStream(); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(1024U, request->bodyLength()); + response_->waitForEndStream(); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(1024U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } void BaseIntegrationTest::testGrpcRetry() { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; Http::TestHeaderMapImpl response_trailers{{"response1", "trailer1"}, {"grpc-status", "0"}}; executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); }, [&]() -> void { - Http::StreamEncoder* request_encoder; - request_encoder = &codec_client->startRequest( + request_encoder_ = &codec_client_->startRequest( Http::TestHeaderMapImpl{{":method", "POST"}, {":path", "/test/long/url"}, {":scheme", "http"}, {":authority", "host"}, {"x-forwarded-for", "10.0.0.1"}, {"x-envoy-retry-grpc-on", "cancelled"}}, - *response); - codec_client->sendData(*request_encoder, 1024, true); + *response_); + codec_client_->sendData(*request_encoder_, 1024, true); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}, {"grpc-status", "1"}}, - false); + upstream_request_->encodeHeaders( + Http::TestHeaderMapImpl{{":status", "200"}, {"grpc-status", "1"}}, false); }, [&]() -> void { if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - fake_upstream_connection->waitForDisconnect(); - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_->waitForDisconnect(); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); } else { - request->waitForReset(); + upstream_request_->waitForReset(); } }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(512, - fake_upstreams_[0]->httpType() != FakeHttpConnection::Type::HTTP2); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, fake_upstreams_[0]->httpType() != + FakeHttpConnection::Type::HTTP2); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { - request->encodeTrailers(response_trailers); + upstream_request_->encodeTrailers(response_trailers); } }, [&]() -> void { - response->waitForEndStream(); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(1024U, request->bodyLength()); + response_->waitForEndStream(); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(1024U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { - EXPECT_THAT(*response->trailers(), HeaderMapEqualRef(&response_trailers)); + EXPECT_THAT(*response_->trailers(), HeaderMapEqualRef(&response_trailers)); } }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } void BaseIntegrationTest::testTwoRequests(Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + {[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, // Request 1. [&]() -> void { - codec_client->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - 1024, *response); + codec_client_->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + 1024, *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(512, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, true); }, [&]() -> void { - response->waitForEndStream(); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(1024U, request->bodyLength()); + response_->waitForEndStream(); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(1024U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); }, // Request 2. [&]() -> void { - response.reset(new IntegrationStreamDecoder(*dispatcher_)); - codec_client->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - 512, *response); + response_.reset(new IntegrationStreamDecoder(*dispatcher_)); + codec_client_->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + 512, *response_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - request->encodeData(1024, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(1024, true); }, [&]() -> void { - response->waitForEndStream(); - EXPECT_TRUE(request->complete()); - EXPECT_EQ(512U, request->bodyLength()); + response_->waitForEndStream(); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(512U, upstream_request_->bodyLength()); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(1024U, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(1024U, response_->body().size()); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } void BaseIntegrationTest::sendRawHttpAndWaitForResponse(const char* raw_http, @@ -1062,93 +1019,85 @@ void BaseIntegrationTest::testBadPath() { } void BaseIntegrationTest::testValidZeroLengthContent(Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeHttpConnectionPtr fake_upstream_connection; - FakeStreamPtr request; executeActions( - {[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + {[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}, - {"content-length", "0"}}, - *response); + codec_client_->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}, + {"content-length", "0"}}, + *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); }, - [&]() -> void { response->waitForEndStream(); }, + [&]() -> void { response_->waitForEndStream(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); - ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + ASSERT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); } void BaseIntegrationTest::testInvalidContentLength(Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - executeActions({[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + executeActions({[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":authority", "host"}, - {"content-length", "-1"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":authority", "host"}, + {"content-length", "-1"}}, + *response_); }, [&]() -> void { if (type == Http::CodecClient::Type::HTTP1) { - codec_client->waitForDisconnect(); + codec_client_->waitForDisconnect(); } else { - response->waitForReset(); - codec_client->close(); + response_->waitForReset(); + codec_client_->close(); } }}); if (type == Http::CodecClient::Type::HTTP1) { - ASSERT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); + ASSERT_TRUE(response_->complete()); + EXPECT_STREQ("400", response_->headers().Status()->value().c_str()); } else { - ASSERT_TRUE(response->reset()); - EXPECT_EQ(Http::StreamResetReason::RemoteReset, response->reset_reason()); + ASSERT_TRUE(response_->reset()); + EXPECT_EQ(Http::StreamResetReason::RemoteReset, response_->reset_reason()); } } void BaseIntegrationTest::testMultipleContentLengths(Http::CodecClient::Type type) { - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - executeActions({[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + executeActions({[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":authority", "host"}, - {"content-length", "3,2"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":authority", "host"}, + {"content-length", "3,2"}}, + *response_); }, [&]() -> void { if (type == Http::CodecClient::Type::HTTP1) { - codec_client->waitForDisconnect(); + codec_client_->waitForDisconnect(); } else { - response->waitForReset(); - codec_client->close(); + response_->waitForReset(); + codec_client_->close(); } }}); if (type == Http::CodecClient::Type::HTTP1) { - ASSERT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); + ASSERT_TRUE(response_->complete()); + EXPECT_STREQ("400", response_->headers().Status()->value().c_str()); } else { - ASSERT_TRUE(response->reset()); - EXPECT_EQ(Http::StreamResetReason::RemoteReset, response->reset_reason()); + ASSERT_TRUE(response_->reset()); + EXPECT_EQ(Http::StreamResetReason::RemoteReset, response_->reset_reason()); } } @@ -1157,32 +1106,28 @@ void BaseIntegrationTest::testOverlyLongHeaders(Http::CodecClient::Type type) { {":method", "GET"}, {":path", "/test/long/url"}, {":scheme", "http"}, {":authority", "host"}}; big_headers.addCopy("big", std::string(60 * 1024, 'a')); - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - executeActions({[&]() -> void { codec_client = makeHttpConnection(lookupPort("http"), type); }, + executeActions({[&]() -> void { codec_client_ = makeHttpConnection(lookupPort("http"), type); }, [&]() -> void { std::string long_value(7500, 'x'); - codec_client->startRequest(big_headers, *response); + codec_client_->startRequest(big_headers, *response_); }, - [&]() -> void { codec_client->waitForDisconnect(); }}); + [&]() -> void { codec_client_->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("431", response->headers().Status()->value().c_str()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("431", response_->headers().Status()->value().c_str()); } void BaseIntegrationTest::testUpstreamProtocolError() { - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); FakeRawConnectionPtr fake_upstream_connection; executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); }, [&]() -> void { - codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":authority", "host"}}, - *response); + codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":authority", "host"}}, + *response_); }, [&]() -> void { fake_upstream_connection = fake_upstreams_[0]->waitForRawConnection(); }, // TODO(mattklein123): Waiting for exact amount of data is a hack. This needs to @@ -1190,118 +1135,108 @@ void BaseIntegrationTest::testUpstreamProtocolError() { [&]() -> void { fake_upstream_connection->waitForData(187); }, [&]() -> void { fake_upstream_connection->write("bad protocol data!"); }, [&]() -> void { fake_upstream_connection->waitForDisconnect(); }, - [&]() -> void { codec_client->waitForDisconnect(); }}); + [&]() -> void { codec_client_->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("503", response_->headers().Status()->value().c_str()); } void BaseIntegrationTest::testDownstreamResetBeforeResponseComplete() { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - Http::StreamEncoder* downstream_request{}; - FakeStreamPtr upstream_request; std::list> actions = { [&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP2); }, [&]() -> void { - downstream_request = - &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}, - {"cookie", "a=b"}, - {"cookie", "c=d"}}, - *response); - codec_client->sendData(*downstream_request, 0, true); + request_encoder_ = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}, + {"cookie", "a=b"}, + {"cookie", "c=d"}}, + *response_); + codec_client_->sendData(*request_encoder_, 0, true); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request = fake_upstream_connection->waitForNewStream(); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, [&]() -> void { - upstream_request->waitForEndStream(*dispatcher_); - EXPECT_EQ(upstream_request->headers().get(Http::Headers::get().Cookie)->value(), + upstream_request_->waitForEndStream(*dispatcher_); + EXPECT_EQ(upstream_request_->headers().get(Http::Headers::get().Cookie)->value(), "a=b; c=d"); }, [&]() -> void { - upstream_request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - upstream_request->encodeData(512, false); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(512, false); }, - [&]() -> void { response->waitForBodyData(512); }, - [&]() -> void { codec_client->sendReset(*downstream_request); }}; + [&]() -> void { response_->waitForBodyData(512); }, + [&]() -> void { codec_client_->sendReset(*request_encoder_); }}; if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } else { - actions.push_back([&]() -> void { upstream_request->waitForReset(); }); - actions.push_back([&]() -> void { fake_upstream_connection->close(); }); - actions.push_back([&]() -> void { fake_upstream_connection->waitForDisconnect(); }); + actions.push_back([&]() -> void { upstream_request_->waitForReset(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->close(); }); + actions.push_back([&]() -> void { fake_upstream_connection_->waitForDisconnect(); }); } - actions.push_back([&]() -> void { codec_client->close(); }); + actions.push_back([&]() -> void { codec_client_->close(); }); executeActions(actions); - EXPECT_TRUE(upstream_request->complete()); - EXPECT_EQ(0U, upstream_request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(0U, upstream_request_->bodyLength()); - EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(512U, response->body().size()); + EXPECT_FALSE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(512U, response_->body().size()); } void BaseIntegrationTest::testTrailers(uint64_t request_size, uint64_t response_size) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - Http::StreamEncoder* request_encoder; - FakeStreamPtr upstream_request; Http::TestHeaderMapImpl request_trailers{{"request1", "trailer1"}, {"request2", "trailer2"}}; Http::TestHeaderMapImpl response_trailers{{"response1", "trailer1"}, {"response2", "trailer2"}}; executeActions( {[&]() -> void { - codec_client = + codec_client_ = makeHttpConnection(lookupPort("http_buffer"), Http::CodecClient::Type::HTTP2); }, [&]() -> void { - request_encoder = - &codec_client->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - *response); - codec_client->sendData(*request_encoder, request_size, false); - codec_client->sendTrailers(*request_encoder, request_trailers); + request_encoder_ = + &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + *response_); + codec_client_->sendData(*request_encoder_, request_size, false); + codec_client_->sendTrailers(*request_encoder_, request_trailers); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { upstream_request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { - upstream_request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); - upstream_request->encodeData(response_size, false); - upstream_request->encodeTrailers(response_trailers); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); + upstream_request_->encodeData(response_size, false); + upstream_request_->encodeTrailers(response_trailers); }, - [&]() -> void { response->waitForEndStream(); }, + [&]() -> void { response_->waitForEndStream(); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); - EXPECT_TRUE(upstream_request->complete()); - EXPECT_EQ(request_size, upstream_request->bodyLength()); + EXPECT_TRUE(upstream_request_->complete()); + EXPECT_EQ(request_size, upstream_request_->bodyLength()); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { - EXPECT_THAT(*upstream_request->trailers(), HeaderMapEqualRef(&request_trailers)); + EXPECT_THAT(*upstream_request_->trailers(), HeaderMapEqualRef(&request_trailers)); } - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_EQ(response_size, response->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(response_size, response_->body().size()); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { - EXPECT_THAT(*response->trailers(), HeaderMapEqualRef(&response_trailers)); + EXPECT_THAT(*response_->trailers(), HeaderMapEqualRef(&response_trailers)); } } } // namespace Envoy diff --git a/test/integration/integration.h b/test/integration/integration.h index 62751f59200e..6a86c4daa534 100644 --- a/test/integration/integration.h +++ b/test/integration/integration.h @@ -244,6 +244,17 @@ class BaseIntegrationTest : Logger::Loggable { void testDownstreamResetBeforeResponseComplete(); void testTrailers(uint64_t request_size, uint64_t response_size); + // The client making requests to Envoy. + IntegrationCodecClientPtr codec_client_; + // A placeholder for the first upstream connection. + FakeHttpConnectionPtr fake_upstream_connection_; + // A placeholder for the first response received by the client. + IntegrationStreamDecoderPtr response_{new IntegrationStreamDecoder(*dispatcher_)}; + // A placeholder for the first request received at upstream. + FakeStreamPtr upstream_request_; + // A pointer to the request encoder, if used. + Http::StreamEncoder* request_encoder_{nullptr}; + std::vector> fake_upstreams_; spdlog::level::level_enum default_log_level_; IntegrationTestServerPtr test_server_; diff --git a/test/integration/integration_test.cc b/test/integration/integration_test.cc index 4e038bf0caeb..f542ab29963e 100644 --- a/test/integration/integration_test.cc +++ b/test/integration/integration_test.cc @@ -30,24 +30,22 @@ TEST_P(IntegrationTest, RouterRedirect) { testRouterRedirect(Http::CodecClient:: TEST_P(IntegrationTest, DrainClose) { testDrainClose(Http::CodecClient::Type::HTTP1); } TEST_P(IntegrationTest, ConnectionClose) { - IntegrationCodecClientPtr codec_client; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); }, [&]() -> void { - codec_client->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/healthcheck"}, - {":authority", "host"}, - {"connection", "close"}}, - *response); + codec_client_->makeHeaderOnlyRequest(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/healthcheck"}, + {":authority", "host"}, + {"connection", "close"}}, + *response_); }, - [&]() -> void { response->waitForEndStream(); }, - [&]() -> void { codec_client->waitForDisconnect(); }}); + [&]() -> void { response_->waitForEndStream(); }, + [&]() -> void { codec_client_->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); } TEST_P(IntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) { @@ -270,34 +268,30 @@ class BindIntegrationTest : public IntegrationTest { }; TEST_P(BindIntegrationTest, TestBind) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr request; executeActions( {[&]() -> void { - codec_client = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); + codec_client_ = makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1); }, // Request 1. [&]() -> void { - codec_client->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, - {":path", "/test/long/url"}, - {":scheme", "http"}, - {":authority", "host"}}, - 1024, *response); + codec_client_->makeRequestWithBody(Http::TestHeaderMapImpl{{":method", "GET"}, + {":path", "/test/long/url"}, + {":scheme", "http"}, + {":authority", "host"}}, + 1024, *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); std::string address = - fake_upstream_connection->connection().remoteAddress().ip()->addressAsString(); + fake_upstream_connection_->connection().remoteAddress().ip()->addressAsString(); EXPECT_EQ(address, address_string_); }, - [&]() -> void { request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); } INSTANTIATE_TEST_CASE_P(IpVersions, BindIntegrationTest, diff --git a/test/integration/ratelimit_integration_test.cc b/test/integration/ratelimit_integration_test.cc index 03950d13f934..98c86352a2e7 100644 --- a/test/integration/ratelimit_integration_test.cc +++ b/test/integration/ratelimit_integration_test.cc @@ -21,8 +21,6 @@ class RatelimitIntegrationTest : public BaseIntegrationTest, fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); registerPort("upstream_1", fake_upstreams_.back()->localAddress()->ip()->port()); createTestServer("test/config/integration/server_ratelimit.json", {"http"}); - - upstream_response_.reset(new IntegrationStreamDecoder(*dispatcher_)); } void TearDown() override { @@ -36,7 +34,7 @@ class RatelimitIntegrationTest : public BaseIntegrationTest, Http::TestHeaderMapImpl headers{{":method", "POST"}, {":path", "/test/long/url"}, {":scheme", "http"}, {":authority", "host"}, {"x-lyft-user-id", "123"}, {"x-forwarded-for", "10.0.0.1"}}; - codec_client_->makeRequestWithBody(headers, request_size_, *upstream_response_); + codec_client_->makeRequestWithBody(headers, request_size_, *response_); } void waitForRatelimitRequest() { @@ -73,21 +71,21 @@ class RatelimitIntegrationTest : public BaseIntegrationTest, upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false); upstream_request_->encodeData(response_size_, true); - upstream_response_->waitForEndStream(); + response_->waitForEndStream(); EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(request_size_, upstream_request_->bodyLength()); - EXPECT_TRUE(upstream_response_->complete()); - EXPECT_STREQ("200", upstream_response_->headers().Status()->value().c_str()); - EXPECT_EQ(response_size_, upstream_response_->body().size()); + EXPECT_TRUE(response_->complete()); + EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ(response_size_, response_->body().size()); } void waitForFailedUpstreamResponse(uint32_t response_code) { - upstream_response_->waitForEndStream(); - EXPECT_TRUE(upstream_response_->complete()); + response_->waitForEndStream(); + EXPECT_TRUE(response_->complete()); EXPECT_STREQ(std::to_string(response_code).c_str(), - upstream_response_->headers().Status()->value().c_str()); + response_->headers().Status()->value().c_str()); } void sendRateLimitResponse(pb::lyft::ratelimit::RateLimitResponse_Code code) { @@ -111,11 +109,7 @@ class RatelimitIntegrationTest : public BaseIntegrationTest, } } - IntegrationCodecClientPtr codec_client_; - FakeHttpConnectionPtr fake_upstream_connection_; FakeHttpConnectionPtr fake_ratelimit_connection_; - IntegrationStreamDecoderPtr upstream_response_; - FakeStreamPtr upstream_request_; FakeStreamPtr ratelimit_request_; const uint64_t request_size_ = 1024; diff --git a/test/integration/xfcc_integration_test.cc b/test/integration/xfcc_integration_test.cc index 25e566168d9d..fd05482193c2 100644 --- a/test/integration/xfcc_integration_test.cc +++ b/test/integration/xfcc_integration_test.cc @@ -123,10 +123,6 @@ void XfccIntegrationTest::startTestServerWithXfccConfig(std::string fcc, std::st void XfccIntegrationTest::testRequestAndResponseWithXfccHeader(Network::ClientConnectionPtr&& conn, std::string previous_xfcc, std::string expected_xfcc) { - IntegrationCodecClientPtr codec_client; - FakeHttpConnectionPtr fake_upstream_connection; - IntegrationStreamDecoderPtr response(new IntegrationStreamDecoder(*dispatcher_)); - FakeStreamPtr upstream_request; Http::TestHeaderMapImpl header_map; if (previous_xfcc.empty()) { header_map = Http::TestHeaderMapImpl{{":method", "GET"}, @@ -143,33 +139,33 @@ void XfccIntegrationTest::testRequestAndResponseWithXfccHeader(Network::ClientCo executeActions( {[&]() -> void { - codec_client = makeHttpConnection(std::move(conn), Http::CodecClient::Type::HTTP1); + codec_client_ = makeHttpConnection(std::move(conn), Http::CodecClient::Type::HTTP1); }, - [&]() -> void { codec_client->makeHeaderOnlyRequest(header_map, *response); }, + [&]() -> void { codec_client_->makeHeaderOnlyRequest(header_map, *response_); }, [&]() -> void { - fake_upstream_connection = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); + fake_upstream_connection_ = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_); }, - [&]() -> void { upstream_request = fake_upstream_connection->waitForNewStream(); }, - [&]() -> void { upstream_request->waitForEndStream(*dispatcher_); }, + [&]() -> void { upstream_request_ = fake_upstream_connection_->waitForNewStream(); }, + [&]() -> void { upstream_request_->waitForEndStream(*dispatcher_); }, [&]() -> void { if (expected_xfcc.empty()) { - EXPECT_EQ(nullptr, upstream_request->headers().ForwardedClientCert()); + EXPECT_EQ(nullptr, upstream_request_->headers().ForwardedClientCert()); } else { EXPECT_STREQ(expected_xfcc.c_str(), - upstream_request->headers().ForwardedClientCert()->value().c_str()); + upstream_request_->headers().ForwardedClientCert()->value().c_str()); } - upstream_request->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); + upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); }, [&]() -> void { - response->waitForEndStream(); - EXPECT_TRUE(upstream_request->complete()); + response_->waitForEndStream(); + EXPECT_TRUE(upstream_request_->complete()); }, // Cleanup both downstream and upstream - [&]() -> void { codec_client->close(); }, - [&]() -> void { fake_upstream_connection->close(); }, - [&]() -> void { fake_upstream_connection->waitForDisconnect(); }}); - EXPECT_TRUE(response->complete()); + [&]() -> void { codec_client_->close(); }, + [&]() -> void { fake_upstream_connection_->close(); }, + [&]() -> void { fake_upstream_connection_->waitForDisconnect(); }}); + EXPECT_TRUE(response_->complete()); } INSTANTIATE_TEST_CASE_P(IpVersions, XfccIntegrationTest,