return wheel_ != nullptr;
}
+ /**
+ * Get the time remaining until this timeout expires. Return 0 if this
+ * timeout is not scheduled or expired. Otherwise, return expiration time
+ * minus getCurTime().
+ */
+ std::chrono::milliseconds getTimeRemaining() {
+ return getTimeRemaining(getCurTime());
+ }
+
protected:
/**
* Don't override this unless you're doing a test. This is mainly here so
T_CHECK_TIMEOUT(start, t3.timestamps[0], milliseconds(10));
T_CHECK_TIMEOUT(start, end, milliseconds(10));
}
+
+TEST_F(HHWheelTimerTest, GetTimeRemaining) {
+ StackWheelTimer t(&eventBase, milliseconds(1));
+ TestTimeout t1;
+
+ // Not scheduled yet, time remaining should be zero
+ ASSERT_EQ(t1.getTimeRemaining(), milliseconds(0));
+ ASSERT_EQ(t.count(), 0);
+
+ // Scheduled, time remaining should be less than or equal to the scheduled
+ // timeout
+ t.scheduleTimeout(&t1, milliseconds(10));
+ ASSERT_LE(t1.getTimeRemaining(), milliseconds(10));
+
+ TimePoint start;
+ eventBase.loop();
+ TimePoint end;
+
+ // Expired and time remaining should be zero
+ ASSERT_EQ(t1.getTimeRemaining(), milliseconds(0));
+
+ ASSERT_EQ(t.count(), 0);
+ T_CHECK_TIMEOUT(start, end, milliseconds(10));
+}