folly copyright 2015 -> copyright 2016
[folly.git] / folly / io / async / test / NotificationQueueTest.cpp
index 2bfc13654b41e8241a0418f8b0f17863f5919277..f8e1e51ab01e9e7c94a328cb9c6ca411c76af7d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -436,9 +436,7 @@ TEST(NotificationQueueTest, ConsumeUntilDrained) {
 
   // Make sure there can only be one drainer at once
   folly::Baton<> callbackBaton, threadStartBaton;
-  consumer.fn = [&](int i) {
-    callbackBaton.wait();
-  };
+  consumer.fn = [&](int /* i */) { callbackBaton.wait(); };
   QueueConsumer competingConsumer;
   competingConsumer.startConsuming(&eventBase, &queue);
   queue.putMessage(1);
@@ -487,9 +485,7 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) {
 
     // Make sure there can only be one drainer at once
     folly::Baton<> callbackBaton, threadStartBaton;
-    consumer.fn = [&](int i) {
-      callbackBaton.wait();
-    };
+    consumer.fn = [&](int /* i */) { callbackBaton.wait(); };
     QueueConsumer competingConsumer;
     competingConsumer.startConsuming(&eventBase, &queue);
     queue.putMessage(1);
@@ -572,11 +568,11 @@ TEST(NotificationQueueTest, DestroyCallbackPipe) {
 }
 
 /*
- * Test code that creates a TNotificationQueue, then forks, and incorrectly
+ * Test code that creates a NotificationQueue, then forks, and incorrectly
  * tries to send a message to the queue from the child process.
  *
  * The child process should crash in this scenario, since the child code has a
- * bug.  (Older versions of TNotificationQueue didn't catch this in the child,
+ * bug.  (Older versions of NotificationQueue didn't catch this in the child,
  * resulting in a crash in the parent process.)
  */
 TEST(NotificationQueueTest, UseAfterFork) {
@@ -631,7 +627,7 @@ TEST(NotificationQueueTest, UseAfterFork) {
   }
 
   // The child process should have crashed when it tried to call putMessage()
-  // on our TNotificationQueue.
+  // on our NotificationQueue.
   EXPECT_TRUE(WIFSIGNALED(childStatus));
   EXPECT_EQ(SIGABRT, WTERMSIG(childStatus));
 
@@ -644,3 +640,21 @@ TEST(NotificationQueueTest, UseAfterFork) {
   EXPECT_EQ(5678, consumer.messages.front());
   consumer.messages.pop_front();
 }
+
+TEST(NotificationQueueConsumer, make) {
+  int value = 0;
+  EventBase evb;
+  NotificationQueue<int> queue(32);
+
+  auto consumer = decltype(queue)::Consumer::make([&](
+      int&& msg) noexcept { value = msg; });
+
+  consumer->startConsuming(&evb, &queue);
+
+  int const newValue = 10;
+  queue.tryPutMessage(newValue);
+
+  evb.loopOnce();
+
+  EXPECT_EQ(newValue, value);
+}