Skip to content

Commit 7fac552

Browse files
committed
cc cache: rewrite cache metrics test without Sleep
commit_hash:497182db302efe8a0dd897ed1a508f0018d00c5d
1 parent b76fcf5 commit 7fac552

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.mapping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@
12081208
"core/src/cache/cache_config.cpp":"taxi/uservices/userver/core/src/cache/cache_config.cpp",
12091209
"core/src/cache/cache_dependencies.cpp":"taxi/uservices/userver/core/src/cache/cache_dependencies.cpp",
12101210
"core/src/cache/cache_dependencies.hpp":"taxi/uservices/userver/core/src/cache/cache_dependencies.hpp",
1211+
"core/src/cache/cache_metrics_initialization_test.cpp":"taxi/uservices/userver/core/src/cache/cache_metrics_initialization_test.cpp",
12111212
"core/src/cache/cache_statistics.cpp":"taxi/uservices/userver/core/src/cache/cache_statistics.cpp",
12121213
"core/src/cache/cache_update_trait.cpp":"taxi/uservices/userver/core/src/cache/cache_update_trait.cpp",
12131214
"core/src/cache/cache_update_trait_impl.cpp":"taxi/uservices/userver/core/src/cache/cache_update_trait_impl.cpp",
@@ -1298,7 +1299,6 @@
12981299
"core/src/clients/http/streamed_response.cpp":"taxi/uservices/userver/core/src/clients/http/streamed_response.cpp",
12991300
"core/src/clients/http/testsuite.hpp":"taxi/uservices/userver/core/src/clients/http/testsuite.hpp",
13001301
"core/src/clients/http/tracing_manager_test.cpp":"taxi/uservices/userver/core/src/clients/http/tracing_manager_test.cpp",
1301-
"core/src/components/cache_metrics_initialization_test.cpp":"taxi/uservices/userver/core/src/components/cache_metrics_initialization_test.cpp",
13021302
"core/src/components/common_component_list.cpp":"taxi/uservices/userver/core/src/components/common_component_list.cpp",
13031303
"core/src/components/common_component_list_test.cpp":"taxi/uservices/userver/core/src/components/common_component_list_test.cpp",
13041304
"core/src/components/common_server_component_list.cpp":"taxi/uservices/userver/core/src/components/common_server_component_list.cpp",

core/src/components/cache_metrics_initialization_test.cpp renamed to core/src/cache/cache_metrics_initialization_test.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <userver/components/run.hpp>
1111
#include <userver/components/statistics_storage.hpp>
1212
#include <userver/engine/deadline.hpp>
13+
#include <userver/engine/single_consumer_event.hpp>
1314
#include <userver/engine/sleep.hpp>
1415
#include <userver/testsuite/testsuite_support.hpp>
1516
#include <userver/utest/utest.hpp>
@@ -19,6 +20,8 @@ USERVER_NAMESPACE_BEGIN
1920

2021
namespace {
2122

23+
engine::SingleConsumerEvent checked_metrics_before_update;
24+
2225
const auto kStaticConfig = tests::MergeYaml(tests::kMinimalStaticConfig, R"(
2326
components_manager:
2427
components:
@@ -47,8 +50,9 @@ class ToyCache final : public components::CachingComponentBase<int> {
4750
const std::chrono::system_clock::time_point& /*now*/,
4851
cache::UpdateStatisticsScope& stats_scope
4952
) override {
50-
// Simulate a 3-second update.
51-
engine::SleepFor(std::chrono::seconds(3));
53+
// Wait until the checker component checks metrics at least once.
54+
const bool wait_succeeded = checked_metrics_before_update.WaitForEventFor(utest::kMaxTestWaitTime);
55+
EXPECT_TRUE(wait_succeeded) << "Timed out waiting for metrics checker";
5256

5357
// Complete successfully with size 10.
5458
Set(10);
@@ -98,6 +102,9 @@ class MetricsChecker final : public components::ComponentBase {
98102
cache_size_seen = true;
99103
}
100104

105+
// Signal to the cache that we checked the metrics state.
106+
checked_metrics_before_update.Send();
107+
101108
// If both metrics are set, we're done.
102109
if (cache_age_seen && cache_size_seen) {
103110
break;
@@ -115,6 +122,8 @@ class CacheMetricsInitializationTest : public ComponentList {};
115122
} // namespace
116123

117124
TEST_F(CacheMetricsInitializationTest, MetricsNotWrittenBeforeInitialization) {
125+
checked_metrics_before_update.Reset();
126+
118127
components::RunOnce(
119128
components::InMemoryConfig{kStaticConfig},
120129
components::MinimalComponentList()

0 commit comments

Comments
 (0)