Commit 818e09c0 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

fix some ASAN crashes in EventBaseTest

Summary:
Since D3640289 the EventBase destructor has invoked currently scheduled
LoopCallbacks.

Some of the tests in `EventBaseTest` installed loop callbacks and checked that
they were never run during the normal loop invocations.  Prior to D3640289
these callbacks never ran.  However, post D3640289 these functions do run, and
they attempt to update local stack variables that have already gone out of
scope.

This rearranges these functions to ensure the variables in question outlive
the EventBase object.

Reviewed By: yfeldblum

Differential Revision: D15462319

fbshipit-source-id: 8f490ddbb978fe45711eb7cbda4502dd6a0fb36b
parent d128502f
......@@ -1412,15 +1412,19 @@ TEST(EventBaseTest, messageAvailableException) {
}
TEST(EventBaseTest, TryRunningAfterTerminate) {
EventBase eventBase;
CountedLoopCallback c1(
&eventBase, 1, std::bind(&EventBase::terminateLoopSoon, &eventBase));
eventBase.runInLoop(&c1);
eventBase.loopForever();
bool ran = false;
eventBase.runInEventBaseThread([&]() { ran = true; });
{
EventBase eventBase;
CountedLoopCallback c1(
&eventBase, 1, std::bind(&EventBase::terminateLoopSoon, &eventBase));
eventBase.runInLoop(&c1);
eventBase.loopForever();
eventBase.runInEventBaseThread([&]() { ran = true; });
ASSERT_FALSE(ran);
ASSERT_FALSE(ran);
}
// Loop callbacks are triggered on EventBase destruction
ASSERT_TRUE(ran);
}
// Test cancelling runInLoop() callbacks
......@@ -1732,23 +1736,28 @@ TEST(EventBaseTest, IdleTime) {
* Test that thisLoop functionality works with terminateLoopSoon
*/
TEST(EventBaseTest, ThisLoop) {
EventBase eb;
bool runInLoop = false;
bool runThisLoop = false;
eb.runInLoop(
[&]() {
eb.terminateLoopSoon();
eb.runInLoop([&]() { runInLoop = true; });
eb.runInLoop([&]() { runThisLoop = true; }, true);
},
true);
eb.loopForever();
// Should not work
ASSERT_FALSE(runInLoop);
// Should work with thisLoop
ASSERT_TRUE(runThisLoop);
{
EventBase eb;
eb.runInLoop(
[&]() {
eb.terminateLoopSoon();
eb.runInLoop([&]() { runInLoop = true; });
eb.runInLoop([&]() { runThisLoop = true; }, true);
},
true);
eb.loopForever();
// Should not work
ASSERT_FALSE(runInLoop);
// Should work with thisLoop
ASSERT_TRUE(runThisLoop);
}
// Pending loop callbacks will be run when the EventBase is destroyed.
ASSERT_TRUE(runInLoop);
}
TEST(EventBaseTest, EventBaseThreadLoop) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment