Test creation of RequestContext inside a fiber task
authorMirek Klimos <miro@fb.com>
Fri, 13 May 2016 21:17:12 +0000 (14:17 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Fri, 13 May 2016 21:23:25 +0000 (14:23 -0700)
Summary: ^, as discussed on D3279644

Reviewed By: andriigrynenko

Differential Revision: D3299473

fbshipit-source-id: dc302132db64399f768d69c641f848d0da1075c4

folly/experimental/fibers/test/FibersTest.cpp

index c19e95a0a3e3f95853ee87507348206c406b3e0e..c5b14f18e5218d229440597b08c237590eb8d795 100644 (file)
@@ -1236,10 +1236,11 @@ TEST(FiberManager, RequestContext) {
   bool checkRun1 = false;
   bool checkRun2 = false;
   bool checkRun3 = false;
-
+  bool checkRun4 = false;
   folly::fibers::Baton baton1;
   folly::fibers::Baton baton2;
   folly::fibers::Baton baton3;
+  folly::fibers::Baton baton4;
 
   folly::RequestContext::create();
   auto rcontext1 = folly::RequestContext::get();
@@ -1276,6 +1277,15 @@ TEST(FiberManager, RequestContext) {
         checkRun3 = true;
       });
 
+  folly::RequestContext::setContext(nullptr);
+  fm.addTask([&]() {
+    folly::RequestContext::create();
+    auto rcontext4 = folly::RequestContext::get();
+    baton4.wait();
+    EXPECT_EQ(rcontext4, folly::RequestContext::get());
+    checkRun4 = true;
+  });
+
   folly::RequestContext::create();
   auto rcontext = folly::RequestContext::get();
 
@@ -1299,6 +1309,12 @@ TEST(FiberManager, RequestContext) {
   fm.loopUntilNoReady();
   EXPECT_TRUE(checkRun3);
   EXPECT_EQ(rcontext, folly::RequestContext::get());
+
+  baton4.post();
+  EXPECT_EQ(rcontext, folly::RequestContext::get());
+  fm.loopUntilNoReady();
+  EXPECT_TRUE(checkRun4);
+  EXPECT_EQ(rcontext, folly::RequestContext::get());
 }
 
 TEST(FiberManager, resizePeriodically) {