minor: subsequent initialization should fail silently (#79)
This commit is contained in:
parent
ec26525b38
commit
0b9bd34354
|
|
@ -122,10 +122,10 @@ class TestDbConfigInitialization:
|
|||
)
|
||||
|
||||
@run_in_subprocess
|
||||
def test_repeated_initialization_runtime_error(self):
|
||||
def test_repeated_initialization(self):
|
||||
# Calling init() repeatedly is allowed:
|
||||
# it succeeds but becomes a no-op after the first successful init()
|
||||
zvec.init()
|
||||
with pytest.raises(RuntimeError):
|
||||
zvec.init()
|
||||
|
||||
|
||||
class TestDbConfigMemoryLimitValidation:
|
||||
|
|
|
|||
|
|
@ -110,8 +110,7 @@ Status GlobalConfig::Initialize(const ConfigData &config) {
|
|||
// Use atomic compare-exchange to ensure only one initialization
|
||||
bool expected = false;
|
||||
if (!initialized_.compare_exchange_strong(expected, true)) {
|
||||
// Already initialized
|
||||
return Status::InvalidArgument("GlobalConfig is already initialized");
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
auto s = Validate(config);
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "zvec/db/config.h"
|
||||
#include <cstdint>
|
||||
#include <gtest/gtest.h>
|
||||
#include "db/common/constants.h"
|
||||
#include "zvec/db/status.h"
|
||||
|
||||
using namespace zvec;
|
||||
|
|
@ -63,16 +61,6 @@ TEST_F(ConfigTest, InitializeWithCustomConsoleLogConfig) {
|
|||
// If already initialized, skip this test
|
||||
GTEST_SKIP() << "GlobalConfig already initialized";
|
||||
}
|
||||
|
||||
ASSERT_TRUE(status.ok()) << "Initialization failed: " << status.message();
|
||||
|
||||
// Verify custom values
|
||||
ASSERT_EQ(GlobalConfig::Instance().memory_limit_bytes(), 1024 * 1024 * 1024);
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_level(),
|
||||
GlobalConfig::LogLevel::DEBUG);
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_type(), "ConsoleLogger");
|
||||
ASSERT_EQ(GlobalConfig::Instance().query_thread_count(), 4);
|
||||
ASSERT_EQ(GlobalConfig::Instance().optimize_thread_count(), 2);
|
||||
}
|
||||
|
||||
TEST_F(ConfigTest, InitializeWithCustomFileLogConfig) {
|
||||
|
|
@ -91,23 +79,9 @@ TEST_F(ConfigTest, InitializeWithCustomFileLogConfig) {
|
|||
// If already initialized, skip this test
|
||||
GTEST_SKIP() << "GlobalConfig already initialized";
|
||||
}
|
||||
|
||||
ASSERT_TRUE(status.ok()) << "Initialization failed: " << status.message();
|
||||
|
||||
// Verify custom values
|
||||
ASSERT_EQ(GlobalConfig::Instance().memory_limit_bytes(),
|
||||
2 * 1024 * 1024 * 1024ULL);
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_level(), GlobalConfig::LogLevel::INFO);
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_type(), "AppendLogger");
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_dir(), "/tmp/logs");
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_file_basename(), "test.log");
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_file_size(), 1024);
|
||||
ASSERT_EQ(GlobalConfig::Instance().log_overdue_days(), 14);
|
||||
ASSERT_EQ(GlobalConfig::Instance().query_thread_count(), 8);
|
||||
ASSERT_EQ(GlobalConfig::Instance().optimize_thread_count(), 4);
|
||||
}
|
||||
|
||||
TEST_F(ConfigTest, DoubleInitializationFails) {
|
||||
TEST_F(ConfigTest, DoubleInitializationSilentlyFails) {
|
||||
GlobalConfig::ConfigData config;
|
||||
|
||||
auto status1 = GlobalConfig::Instance().Initialize(config);
|
||||
|
|
@ -123,10 +97,9 @@ TEST_F(ConfigTest, DoubleInitializationFails) {
|
|||
// First initialization succeeded, second should fail
|
||||
ASSERT_TRUE(status1.ok());
|
||||
|
||||
// The second initialization is allowed but becomes a no-op
|
||||
auto status2 = GlobalConfig::Instance().Initialize(config);
|
||||
ASSERT_FALSE(status2.ok());
|
||||
ASSERT_EQ(status2.code(), StatusCode::INVALID_ARGUMENT);
|
||||
ASSERT_NE(status2.message().find("already initialized"), std::string::npos);
|
||||
ASSERT_TRUE(status2.ok());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue