From e17ef891b321f468ca0d4204b5e522249f17fcaa Mon Sep 17 00:00:00 2001 From: HeYuchen <377710264@qq.com> Date: Fri, 12 Mar 2021 14:18:52 +0800 Subject: [PATCH] fix: update bool app envs (#781) --- src/replica/replica_config.cpp | 3 ++- src/replica/test/replica_test.cpp | 20 +++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/replica/replica_config.cpp b/src/replica/replica_config.cpp index 6fd156786e..062d018fcf 100644 --- a/src/replica/replica_config.cpp +++ b/src/replica/replica_config.cpp @@ -567,11 +567,12 @@ void replica::update_bool_envs(const std::map &envs, const std::string &name, bool &value) { - bool new_value = value; + bool new_value = false; auto iter = envs.find(name); if (iter != envs.end()) { if (!buf2bool(iter->second, new_value)) { dwarn_replica("invalid value of env {}: \"{}\"", name, iter->second); + return; } } if (new_value != value) { diff --git a/src/replica/test/replica_test.cpp b/src/replica/test/replica_test.cpp index 98e4ce3364..ce60b18a35 100644 --- a/src/replica/test/replica_test.cpp +++ b/src/replica/test/replica_test.cpp @@ -159,20 +159,18 @@ TEST_F(replica_test, update_validate_partition_hash_test) { struct update_validate_partition_hash_test { - bool old_value; bool set_in_map; + bool old_value; std::string new_value; bool expected_value; - } tests[]{ - {false, false, "false", false}, - {false, true, "false", false}, - {false, false, "true", false}, - {false, true, "true", true}, - {false, true, "ture", false}, - {true, true, "false", false}, - {true, true, "true", true}, - {true, true, "flase", true}, - }; + } tests[]{{true, false, "false", false}, + {true, false, "true", true}, + {true, true, "true", true}, + {true, true, "false", false}, + {false, false, "", false}, + {false, true, "", false}, + {true, true, "flase", true}, + {true, false, "ture", false}}; for (const auto &test : tests) { update_validate_partition_hash(test.old_value, test.set_in_map, test.new_value); ASSERT_EQ(get_validate_partition_hash(), test.expected_value);