diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp --- a/lldb/unittests/Host/MainLoopTest.cpp +++ b/lldb/unittests/Host/MainLoopTest.cpp @@ -174,8 +174,13 @@ auto handle = loop.RegisterSignal(SIGUSR1, make_callback(), error); ASSERT_TRUE(error.Success()); - kill(getpid(), SIGUSR1); + std::thread killer([]() { + sleep(1); + kill(getpid(), SIGUSR1); + }); ASSERT_TRUE(loop.Run().Success()); + killer.join(); + ASSERT_EQ(1u, callback_count); } @@ -220,8 +225,12 @@ SIGUSR1, [&](MainLoopBase &loop) { ++callback2_count; }, error); ASSERT_TRUE(error.Success()); - kill(getpid(), SIGUSR1); + std::thread killer([]() { + sleep(1); + kill(getpid(), SIGUSR1); + }); ASSERT_TRUE(loop.Run().Success()); + killer.join(); ASSERT_EQ(1u, callback_count); ASSERT_EQ(1u, callback2_count); ASSERT_EQ(0u, callback3_count); @@ -233,18 +242,28 @@ SIGUSR1, [&](MainLoopBase &loop) { ++callback3_count; }, error); ASSERT_TRUE(error.Success()); - kill(getpid(), SIGUSR1); + std::thread killer([]() { + sleep(1); + kill(getpid(), SIGUSR1); + }); ASSERT_TRUE(loop.Run().Success()); + killer.join(); ASSERT_EQ(2u, callback_count); ASSERT_EQ(1u, callback2_count); ASSERT_EQ(1u, callback3_count); } // Both extra callbacks should be unregistered now. - kill(getpid(), SIGUSR1); - ASSERT_TRUE(loop.Run().Success()); - ASSERT_EQ(3u, callback_count); - ASSERT_EQ(1u, callback2_count); - ASSERT_EQ(1u, callback3_count); + { + std::thread killer([]() { + sleep(1); + kill(getpid(), SIGUSR1); + }); + ASSERT_TRUE(loop.Run().Success()); + killer.join(); + ASSERT_EQ(3u, callback_count); + ASSERT_EQ(1u, callback2_count); + ASSERT_EQ(1u, callback3_count); + } } #endif