Add unit test for timeout=0
authorSubodh Iyengar <subodh@fb.com>
Thu, 16 Nov 2017 01:59:20 +0000 (17:59 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 16 Nov 2017 02:10:19 +0000 (18:10 -0800)
Summary:
Add unit test for immediate timeout since
we're using it in a few places.

Reviewed By: yfeldblum

Differential Revision: D6327012

fbshipit-source-id: ea80763d080b06e2a43277118d3147dc8016f348

folly/io/async/test/AsyncTimeoutTest.cpp

index 629d678..1d7c04f 100644 (file)
@@ -53,6 +53,20 @@ TEST(AsyncTimeout, schedule) {
   EXPECT_EQ(expected, value);
 }
 
+TEST(AsyncTimeout, schedule_immediate) {
+  int value = 0;
+  int const expected = 10;
+  EventBase manager;
+
+  auto observer = AsyncTimeout::schedule(
+      std::chrono::milliseconds(0), manager, [&]() noexcept {
+        value = expected;
+      });
+
+  manager.loop();
+  EXPECT_EQ(expected, value);
+}
+
 TEST(AsyncTimeout, cancel_make) {
   int value = 0;
   int const expected = 10;