diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-05 20:42:57 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-05 20:42:57 +0000 |
commit | 35d3636eeee07ed762d789d78f3565af671d8092 (patch) | |
tree | d2cd316b0ca7844d550333794d7abe58a75a1bd7 /config | |
parent | 9f9fd46a80cc6e04a8c2004da93d39c253321f6c (diff) |
Verify that negative time time does mean a very long wait
Diffstat (limited to 'config')
-rw-r--r-- | config/src/tests/configholder/configholder.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/config/src/tests/configholder/configholder.cpp b/config/src/tests/configholder/configholder.cpp index 68a39d2fd2e..cd799d9bfa0 100644 --- a/config/src/tests/configholder/configholder.cpp +++ b/config/src/tests/configholder/configholder.cpp @@ -4,18 +4,25 @@ using namespace config; +namespace { + +constexpr double ONE_SEC = 1000.0; +constexpr double ONE_MINUTE = 60 * ONE_SEC; + +} + TEST("Require that element order is correct") { ConfigValue value(std::vector<vespalib::string>(), "foo"); ConfigValue value2(std::vector<vespalib::string>(), "bar"); ConfigHolder holder; - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); std::unique_ptr<ConfigUpdate> update = holder.provide(); ASSERT_TRUE(value == update->getValue()); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, false, 1))); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value2, false, 2))); + holder.handle(std::make_unique<ConfigUpdate>(value, false, 1)); + holder.handle(std::make_unique<ConfigUpdate>(value2, false, 2)); update = holder.provide(); ASSERT_TRUE(value2 == update->getValue()); } @@ -28,10 +35,10 @@ TEST("Require that waiting is done") FastOS_Time timer; timer.SetNow(); holder.wait(1000); - ASSERT_TRUE(timer.MilliSecsToNow() >= 1000); - ASSERT_TRUE(timer.MilliSecsToNow() < 60000); + EXPECT_GREATER_EQUAL(timer.MilliSecsToNow(), ONE_SEC); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); ASSERT_TRUE(holder.wait(100)); } @@ -41,12 +48,24 @@ TEST("Require that polling for elements work") ConfigHolder holder; ASSERT_FALSE(holder.poll()); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); ASSERT_TRUE(holder.poll()); holder.provide(); ASSERT_FALSE(holder.poll()); } +TEST("Require that negative time does not mean forever.") { + ConfigHolder holder; + FastOS_Time timer; + timer.SetNow(); + ASSERT_FALSE(holder.poll()); + ASSERT_FALSE(holder.wait(10)); + ASSERT_FALSE(holder.wait(0)); + ASSERT_FALSE(holder.wait(-1)); + ASSERT_FALSE(holder.wait(-7)); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); +} + TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) { if (thread_id == 0) { @@ -54,8 +73,8 @@ TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) timer.SetNow(); TEST_BARRIER(); f.wait(1000); - EXPECT_TRUE(timer.MilliSecsToNow() < 60000.0); - EXPECT_TRUE(timer.MilliSecsToNow() > 400.0); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); + EXPECT_GREATER(timer.MilliSecsToNow(), 400.0); TEST_BARRIER(); } else { TEST_BARRIER(); |