@@ -369,6 +369,50 @@ TEST_F(AsyncClientImplTest, OngoingRequestWithWatermarkingAndReset) {
369
369
stream_encoder_.getStream ().resetStream (StreamResetReason::RemoteReset);
370
370
}
371
371
372
+ TEST_F (AsyncClientImplTest, OngoingRequestWithResetAfterCompletion) {
373
+ auto headers = std::make_unique<TestRequestHeaderMapImpl>();
374
+ HttpTestUtility::addDefaultHeaders (*headers);
375
+ TestRequestHeaderMapImpl headers_copy = *headers;
376
+
377
+ Buffer::OwnedImpl data (" test data" );
378
+ const Buffer::OwnedImpl data_copy (data.toString ());
379
+
380
+ EXPECT_CALL (cm_.thread_local_cluster_ .conn_pool_ , newStream (_, _, _))
381
+ .WillOnce (Invoke (
382
+ [&](ResponseDecoder& decoder, ConnectionPool::Callbacks& callbacks,
383
+ const ConnectionPool::Instance::StreamOptions&) -> ConnectionPool::Cancellable* {
384
+ callbacks.onPoolReady (stream_encoder_, cm_.thread_local_cluster_ .conn_pool_ .host_ ,
385
+ stream_info_, {});
386
+ response_decoder_ = &decoder;
387
+ return nullptr ;
388
+ }));
389
+
390
+ headers_copy.addCopy (" x-envoy-internal" , " true" );
391
+ headers_copy.addCopy (" x-forwarded-for" , " 127.0.0.1" );
392
+
393
+ EXPECT_CALL (stream_encoder_, encodeHeaders (HeaderMapEqualRef (&headers_copy), false ));
394
+ EXPECT_CALL (stream_encoder_, encodeData (BufferEqual (&data_copy), true ));
395
+
396
+ AsyncClient::OngoingRequest* request =
397
+ client_.startRequest (std::move (headers), callbacks_, AsyncClient::RequestOptions ());
398
+ EXPECT_NE (request, nullptr );
399
+
400
+ request->sendData (data, true );
401
+
402
+ expectSuccess (request, 200 );
403
+
404
+ ResponseHeaderMapPtr response_headers (new TestResponseHeaderMapImpl{{" :status" , " 200" }});
405
+ response_decoder_->decodeHeaders (std::move (response_headers), true );
406
+
407
+ request->reset ();
408
+ EXPECT_EQ (
409
+ 1UL ,
410
+ cm_.thread_local_cluster_ .cluster_ .info_ ->stats_store_ .counter (" upstream_rq_200" ).value ());
411
+ EXPECT_EQ (1UL , cm_.thread_local_cluster_ .cluster_ .info_ ->stats_store_
412
+ .counter (" internal.upstream_rq_200" )
413
+ .value ());
414
+ }
415
+
372
416
TEST_F (AsyncClientImplTracingTest, Basic) {
373
417
Tracing::MockSpan* child_span{new Tracing::MockSpan ()};
374
418
message_->body ().add (" test body" );
@@ -1444,6 +1488,50 @@ TEST_F(AsyncClientImplTracingTest, CancelRequest) {
1444
1488
request->cancel ();
1445
1489
}
1446
1490
1491
+ TEST_F (AsyncClientImplTracingTest, CancelRequestAfterComplete) {
1492
+ Tracing::MockSpan* child_span{new Tracing::MockSpan ()};
1493
+ EXPECT_CALL (cm_.thread_local_cluster_ .conn_pool_ , newStream (_, _, _))
1494
+ .WillOnce (Invoke (
1495
+ [&](StreamDecoder&, ConnectionPool::Callbacks& callbacks,
1496
+ const ConnectionPool::Instance::StreamOptions&) -> ConnectionPool::Cancellable* {
1497
+ callbacks.onPoolReady (stream_encoder_, cm_.thread_local_cluster_ .conn_pool_ .host_ ,
1498
+ stream_info_, {});
1499
+ return nullptr ;
1500
+ }));
1501
+
1502
+ EXPECT_CALL (parent_span_, spawnChild_ (_, " async fake_cluster egress" , _))
1503
+ .WillOnce (Return (child_span));
1504
+
1505
+ AsyncClient::RequestOptions options = AsyncClient::RequestOptions ().setParentSpan (parent_span_);
1506
+ EXPECT_CALL (*child_span, setSampled (true ));
1507
+ EXPECT_CALL (*child_span, injectContext (_, _));
1508
+ EXPECT_CALL (callbacks_, onBeforeFinalizeUpstreamSpan (_, _))
1509
+ .WillOnce (Invoke ([](Tracing::Span& span, const Http::ResponseHeaderMap* response_headers) {
1510
+ span.setTag (" onBeforeFinalizeUpstreamSpan" , " called" );
1511
+ // Since this is a failure, we expect no response headers.
1512
+ ASSERT_EQ (nullptr , response_headers);
1513
+ }));
1514
+ AsyncClient::Request* request = client_.send (std::move (message_), callbacks_, options);
1515
+
1516
+ EXPECT_CALL (*child_span, setTag (Eq (" onBeforeFinalizeUpstreamSpan" ), Eq (" called" )));
1517
+ EXPECT_CALL (*child_span,
1518
+ setTag (Eq (Tracing::Tags::get ().Component ), Eq (Tracing::Tags::get ().Proxy )));
1519
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().HttpProtocol ), Eq (" HTTP/1.1" )));
1520
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().UpstreamAddress ), Eq (" 10.0.0.1:443" )));
1521
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().PeerAddress ), Eq (" 10.0.0.1:443" )));
1522
+
1523
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().UpstreamCluster ), Eq (" fake_cluster" )));
1524
+ EXPECT_CALL (*child_span,
1525
+ setTag (Eq (Tracing::Tags::get ().UpstreamClusterName ), Eq (" observability_name" )));
1526
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().HttpStatusCode ), Eq (" 0" )));
1527
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().ResponseFlags ), Eq (" -" )));
1528
+ EXPECT_CALL (*child_span, setTag (Eq (Tracing::Tags::get ().Error ), Eq (Tracing::Tags::get ().True )));
1529
+ EXPECT_CALL (*child_span,
1530
+ setTag (Eq (Tracing::Tags::get ().Canceled ), Eq (Tracing::Tags::get ().True )));
1531
+ EXPECT_CALL (*child_span, finishSpan ());
1532
+ request->cancel ();
1533
+ }
1534
+
1447
1535
TEST_F (AsyncClientImplTest, DestroyWithActiveStream) {
1448
1536
EXPECT_CALL (cm_.thread_local_cluster_ .conn_pool_ , newStream (_, _, _))
1449
1537
.WillOnce (Invoke (
0 commit comments