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) { ...@@ -1412,15 +1412,19 @@ TEST(EventBaseTest, messageAvailableException) {
} }
TEST(EventBaseTest, TryRunningAfterTerminate) { TEST(EventBaseTest, TryRunningAfterTerminate) {
EventBase eventBase;
CountedLoopCallback c1(
&eventBase, 1, std::bind(&EventBase::terminateLoopSoon, &eventBase));
eventBase.runInLoop(&c1);
eventBase.loopForever();
bool ran = false; 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 // Test cancelling runInLoop() callbacks
...@@ -1732,23 +1736,28 @@ TEST(EventBaseTest, IdleTime) { ...@@ -1732,23 +1736,28 @@ TEST(EventBaseTest, IdleTime) {
* Test that thisLoop functionality works with terminateLoopSoon * Test that thisLoop functionality works with terminateLoopSoon
*/ */
TEST(EventBaseTest, ThisLoop) { TEST(EventBaseTest, ThisLoop) {
EventBase eb;
bool runInLoop = false; bool runInLoop = false;
bool runThisLoop = false; bool runThisLoop = false;
eb.runInLoop( {
[&]() { EventBase eb;
eb.terminateLoopSoon(); eb.runInLoop(
eb.runInLoop([&]() { runInLoop = true; }); [&]() {
eb.runInLoop([&]() { runThisLoop = true; }, true); eb.terminateLoopSoon();
}, eb.runInLoop([&]() { runInLoop = true; });
true); eb.runInLoop([&]() { runThisLoop = true; }, true);
eb.loopForever(); },
true);
// Should not work eb.loopForever();
ASSERT_FALSE(runInLoop);
// Should work with thisLoop // Should not work
ASSERT_TRUE(runThisLoop); 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) { 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