From e51d8547288a38a828a6110eb390fe19cc8be24c Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Thu, 25 Jun 2015 08:41:28 -0700 Subject: [PATCH] (Wangle) Clean up some data races in tests Summary: Not 100% about the `ThreadWheelTimekeeper` test. It makes TSAN happy though. Reviewed By: @yfeldblum Differential Revision: D2187901 --- folly/futures/detail/ThreadWheelTimekeeper.cpp | 2 +- folly/futures/test/TimekeeperTest.cpp | 3 ++- folly/futures/test/ViaTest.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/folly/futures/detail/ThreadWheelTimekeeper.cpp b/folly/futures/detail/ThreadWheelTimekeeper.cpp index 294b71fa..8b5745d6 100644 --- a/folly/futures/detail/ThreadWheelTimekeeper.cpp +++ b/folly/futures/detail/ThreadWheelTimekeeper.cpp @@ -76,8 +76,8 @@ ThreadWheelTimekeeper::ThreadWheelTimekeeper() : ThreadWheelTimekeeper::~ThreadWheelTimekeeper() { eventBase_.runInEventBaseThreadAndWait([this]{ wheelTimer_->cancelAll(); + eventBase_.terminateLoopSoon(); }); - eventBase_.terminateLoopSoon(); thread_.join(); } diff --git a/folly/futures/test/TimekeeperTest.cpp b/folly/futures/test/TimekeeperTest.cpp index 0ecdb2d7..d913b70d 100644 --- a/folly/futures/test/TimekeeperTest.cpp +++ b/folly/futures/test/TimekeeperTest.cpp @@ -52,8 +52,9 @@ TEST_F(TimekeeperFixture, after) { TEST(Timekeeper, futureGet) { Promise p; - std::thread([&]{ p.setValue(42); }).detach(); + auto t = std::thread([&]{ p.setValue(42); }); EXPECT_EQ(42, p.getFuture().get()); + t.join(); } TEST(Timekeeper, futureGetBeforeTimeout) { diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp index 77466ac4..5027ed91 100644 --- a/folly/futures/test/ViaTest.cpp +++ b/folly/futures/test/ViaTest.cpp @@ -72,7 +72,7 @@ struct ViaFixture : public testing::Test { std::shared_ptr eastExecutor; std::shared_ptr waiter; InlineExecutor inlineExecutor; - bool done; + std::atomic done; std::thread t; }; -- 2.34.1