@@ -14,7 +14,6 @@ USERVER_NAMESPACE_BEGIN
1414
1515using HttpResponse = utest::SimpleServer::Response;
1616using HttpRequest = utest::SimpleServer::Request;
17- using HttpCallback = utest::SimpleServer::OnRequest;
1817
1918static HttpResponse Callback (int code, const HttpRequest& request) {
2019 LOG_INFO () << " HTTP Server receive: " << request;
@@ -30,7 +29,10 @@ static HttpResponse Callback(int code, const HttpRequest& request) {
3029UTEST (DestinationStatistics, Empty) {
3130 auto client = utest::impl::CreateHttpClientCore ();
3231
33- EXPECT_EQ (client->GetDestinationStatistics ().begin (), client->GetDestinationStatistics ().end ());
32+ client->GetDestinationStatistics ()
33+ .VisitAllDebug ([](const clients::http::DestinationLabels&, const clients::http::Statistics&) {
34+ ADD_FAILURE () << " Should be empty" ;
35+ });
3436}
3537
3638UTEST (DestinationStatistics, Ok) {
@@ -41,23 +43,23 @@ UTEST(DestinationStatistics, Ok) {
4143
4244 auto response = client->CreateRequest ().post (url).retry (1 ).timeout (std::chrono::milliseconds (100 )).perform ();
4345
44- const auto & dest_stats = client->GetDestinationStatistics ();
4546 size_t size = 0 ;
46- for (const auto & [stat_url, stat_ptr] : dest_stats) {
47+
48+ const auto visitor = [&](const clients::http::DestinationLabels& labels, const clients::http::Statistics& stat) {
4749 ASSERT_EQ (1 , ++size);
4850
49- EXPECT_EQ (url, stat_url);
50- ASSERT_NE (nullptr , stat_ptr);
51+ EXPECT_EQ (url, *labels.http_destination );
5152
52- auto stats = clients::http::InstanceStatistics (*stat_ptr );
53+ auto stats = clients::http::InstanceStatistics (stat );
5354 auto ok = static_cast <size_t >(clients::http::Statistics::ErrorGroup::kOk );
5455 EXPECT_EQ (utils::statistics::Rate{1 }, stats.error_count [ok]);
5556 for (size_t i = 0 ; i < clients::http::Statistics::kErrorGroupCount ; i++) {
5657 if (i != ok) {
5758 EXPECT_EQ (utils::statistics::Rate{0 }, stats.error_count [i]);
5859 }
5960 }
60- }
61+ };
62+ client->GetDestinationStatistics ().VisitAllDebug (visitor);
6163}
6264
6365UTEST (DestinationStatistics, CancelledFuture) {
@@ -99,25 +101,23 @@ UTEST(DestinationStatistics, Multiple) {
99101 auto response = client->CreateRequest ().post (url).retry (1 ).timeout (std::chrono::milliseconds (100 )).perform ();
100102 response = client->CreateRequest ().post (url2).retry (1 ).timeout (std::chrono::milliseconds (100 )).perform ();
101103
102- const auto & dest_stats = client->GetDestinationStatistics ();
103104 size_t size = 0 ;
104105 std::unordered_set<std::string> expected_urls{url, url2};
105- for (const auto & [stat_url, stat_ptr] : dest_stats ) {
106+ const auto visitor = [&] (const clients::http::DestinationLabels& labels, const clients::http::Statistics& stat ) {
106107 ASSERT_LE (++size, 2 );
107108
108- EXPECT_EQ (1 , expected_urls.erase (stat_url ));
109+ EXPECT_EQ (1 , expected_urls.erase (std::string{labels. http_destination } ));
109110
110- ASSERT_NE (nullptr , stat_ptr);
111-
112- auto stats = clients::http::InstanceStatistics (*stat_ptr);
111+ auto stats = clients::http::InstanceStatistics (stat);
113112 auto ok = static_cast <size_t >(clients::http::Statistics::ErrorGroup::kOk );
114113 EXPECT_EQ (utils::statistics::Rate{1 }, stats.error_count [ok]);
115114 for (size_t i = 0 ; i < clients::http::Statistics::kErrorGroupCount ; i++) {
116115 if (i != ok) {
117116 EXPECT_EQ (utils::statistics::Rate{0 }, stats.error_count [i]) << i << " errors must be zero" ;
118117 }
119118 }
120- }
119+ };
120+ client->GetDestinationStatistics ().VisitAllDebug (visitor);
121121}
122122
123123USERVER_NAMESPACE_END
0 commit comments