// Copyright 2025-present the zvec project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "db/common/global_resource.h" #include #include #include #include using namespace zvec; TEST(GlobalResource, UsesEffectiveCountsAndDisablesBindingByDefault) { GlobalConfig::ConfigData config; config.query_thread_count = 2; config.optimize_thread_count = 1; EXPECT_FALSE(config.query_thread_binding); EXPECT_FALSE(config.optimize_thread_binding); const auto status = GlobalConfig::Instance().Initialize(config); ASSERT_TRUE(status.ok()) << status.message(); EXPECT_FALSE(GlobalConfig::Instance().query_thread_binding()); EXPECT_FALSE(GlobalConfig::Instance().optimize_thread_binding()); const auto max_workers = std::max(std::thread::hardware_concurrency(), 1u); const auto expected_query_workers = std::min( GlobalConfig::Instance().query_thread_count(), max_workers); const auto expected_optimize_workers = std::min( GlobalConfig::Instance().optimize_thread_count(), max_workers); EXPECT_EQ(expected_query_workers, GlobalResource::Instance().query_thread_pool()->count()); EXPECT_EQ(expected_optimize_workers, GlobalResource::Instance().optimize_thread_pool()->count()); }