X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2Fasync%2Ftest%2FEventBaseTest.cpp;h=f8b2b1e068775088f1772dffb6dd22364a2b6562;hp=25b3192c1280751b497b8138b13d9ebadb58be58;hb=bda67fde120837b77ddab74f23abcb22ae5b3029;hpb=5a07e203d79324b68d69f294fa38e43b9671e9b1 diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index 25b3192c..f8b2b1e0 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -1414,7 +1414,7 @@ TEST(EventBaseTest, CancelRunInLoop) { // Run the loop eventBase.loop(); - // cancelC1 and cancelC3 should have both fired after 10 iterations and + // cancelC1 and cancelC2 should have both fired after 10 iterations and // stopped re-installing themselves ASSERT_EQ(cancelC1.getCount(), 0); ASSERT_EQ(cancelC2.getCount(), 0); @@ -1914,15 +1914,44 @@ TEST(EventBaseTest, DrivableExecutorTest) { TEST(EventBaseTest, RequestContextTest) { EventBase evb; auto defaultCtx = RequestContext::get(); + std::weak_ptr rctx_weak_ptr; { RequestContextScopeGuard rctx; + rctx_weak_ptr = RequestContext::saveContext(); auto context = RequestContext::get(); EXPECT_NE(defaultCtx, context); evb.runInLoop([context] { EXPECT_EQ(context, RequestContext::get()); }); + evb.loop(); } + // Ensure that RequestContext created for the scope has been released and + // deleted. + EXPECT_EQ(rctx_weak_ptr.expired(), true); + EXPECT_EQ(defaultCtx, RequestContext::get()); - evb.loop(); +} + +TEST(EventBaseTest, CancelLoopCallbackRequestContextTest) { + EventBase evb; + CountedLoopCallback c(&evb, 1); + + auto defaultCtx = RequestContext::get(); + EXPECT_EQ(defaultCtx, RequestContext::get()); + std::weak_ptr rctx_weak_ptr; + + { + RequestContextScopeGuard rctx; + rctx_weak_ptr = RequestContext::saveContext(); + auto context = RequestContext::get(); + EXPECT_NE(defaultCtx, context); + evb.runInLoop(&c); + c.cancelLoopCallback(); + } + + // Ensure that RequestContext created for the scope has been released and + // deleted. + EXPECT_EQ(rctx_weak_ptr.expired(), true); + EXPECT_EQ(defaultCtx, RequestContext::get()); }