From: Hannes Roth Date: Thu, 25 Jun 2015 15:41:28 +0000 (-0700) Subject: (Wangle) Clean up some data races in tests X-Git-Tag: v0.48.0~12 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e51d8547288a38a828a6110eb390fe19cc8be24c;p=folly.git (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 --- 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; };