Verify that negative time time does mean a very long wait
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();
