Skip to content

Commit 2065b9f

Browse files
committed
[manager] fix location lookup metrics lifecycle test
1 parent 498da76 commit 2065b9f

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

kv_cache_manager/manager/test/cache_manager_test.cc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "kv_cache_manager/meta/meta_local_backend.h"
4242
#include "kv_cache_manager/meta/utils.h"
4343
#include "kv_cache_manager/metrics/metrics_collector.h"
44+
#include "kv_cache_manager/metrics/metrics_lifecycle.h"
4445
#include "kv_cache_manager/metrics/metrics_registry.h"
4546
#include "stub.h"
4647

@@ -601,14 +602,15 @@ class CacheManagerTest : public TESTBASE {
601602
return snapshot_response.committed_snapshot_version();
602603
}
603604

604-
ControllableMetaLocalBackend *InstallControllableMetaBackend() {
605-
auto indexer = cache_manager_->meta_indexer_manager_->GetMetaIndexer("test_instance");
605+
ControllableMetaLocalBackend *
606+
InstallControllableMetaBackend(const std::string &instance_id = "test_instance") {
607+
auto indexer = cache_manager_->meta_indexer_manager_->GetMetaIndexer(instance_id);
606608
if (!indexer) {
607609
return nullptr;
608610
}
609611
auto config = std::make_shared<MetaStorageBackendConfig>();
610612
auto controlled = std::make_unique<ControllableMetaLocalBackend>();
611-
if (controlled->Init("test_instance", config) != EC_OK || controlled->Open() != EC_OK) {
613+
if (controlled->Init(instance_id, config) != EC_OK || controlled->Open() != EC_OK) {
612614
return nullptr;
613615
}
614616
auto *controlled_raw = controlled.get();
@@ -1755,23 +1757,25 @@ TEST_F(CacheManagerTest, TestGetCacheLocationHitRateCounters_ErrorPath) {
17551757
}
17561758

17571759
TEST_F(CacheManagerTest, TestLocationLookupMetricsDoNotReappearAfterInstancePurge) {
1760+
const std::string instance_id = "location_lookup_lifecycle_instance";
17581761
auto expected = std::pair<ErrorCode, std::string>(EC_OK, default_storage_configs);
17591762
ASSERT_EQ(expected,
17601763
cache_manager_->RegisterInstance(request_context_.get(),
17611764
"default",
1762-
"test_instance",
1765+
instance_id,
17631766
64,
17641767
createLocationSpecInfos(),
17651768
createModelDeployment(),
17661769
std::vector<LocationSpecGroup>()));
1767-
auto *controlled_backend = InstallControllableMetaBackend();
1770+
auto *controlled_backend = InstallControllableMetaBackend(instance_id);
17681771
ASSERT_NE(nullptr, controlled_backend);
17691772
controlled_backend->BlockNextLocationRead();
17701773

1771-
auto query_future = std::async(std::launch::async, [manager = cache_manager_]() {
1774+
CacheManager *manager = cache_manager_.get();
1775+
auto query_future = std::async(std::launch::async, [manager, instance_id]() {
17721776
RequestContext context("location_lookup_lifecycle_query");
17731777
return manager->GetCacheLocation(&context,
1774-
"test_instance",
1778+
instance_id,
17751779
CacheManager::QueryType::QT_PREFIX_MATCH,
17761780
{1, 2, 3},
17771781
{},
@@ -1787,13 +1791,11 @@ TEST_F(CacheManagerTest, TestLocationLookupMetricsDoNotReappearAfterInstancePurg
17871791
std::promise<void> purge_started;
17881792
auto purge_started_future = purge_started.get_future();
17891793
auto purge_future = std::async(std::launch::async,
1790-
[manager = cache_manager_, registry = registry_manager_, &purge_started]() {
1794+
[manager, instance_id, &purge_started]() {
17911795
purge_started.set_value();
17921796
std::unique_lock<std::shared_mutex> lifecycle_guard(manager->metrics_lifecycle()->mut_);
17931797
RequestContext remove_context("location_lookup_lifecycle_remove");
1794-
const auto ec = registry->RemoveInstance(&remove_context, "default", "test_instance");
1795-
manager->InvalidateInstanceMetrics("test_instance");
1796-
return ec;
1798+
return manager->RemoveInstance(&remove_context, "default", instance_id);
17971799
});
17981800
purge_started_future.wait();
17991801
EXPECT_EQ(std::future_status::timeout, purge_future.wait_for(std::chrono::milliseconds(50)));
@@ -1807,7 +1809,7 @@ TEST_F(CacheManagerTest, TestLocationLookupMetricsDoNotReappearAfterInstancePurg
18071809
EXPECT_EQ(EC_INSTANCE_NOT_EXIST,
18081810
cache_manager_
18091811
->GetCacheLocation(&post_remove_context,
1810-
"test_instance",
1812+
instance_id,
18111813
CacheManager::QueryType::QT_PREFIX_MATCH,
18121814
{1, 2, 3},
18131815
{},
@@ -1821,7 +1823,10 @@ TEST_F(CacheManagerTest, TestLocationLookupMetricsDoNotReappearAfterInstancePurg
18211823
for (const auto &[name, tags, value] : all_metrics) {
18221824
(void) name;
18231825
(void) value;
1824-
EXPECT_EQ(tags.end(), tags.find("instance_id"));
1826+
auto instance_tag = tags.find("instance_id");
1827+
if (instance_tag != tags.end()) {
1828+
EXPECT_NE(instance_id, instance_tag->second);
1829+
}
18251830
}
18261831
}
18271832

0 commit comments

Comments
 (0)