Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Unified Diff: mojo/message_pump/handle_watcher_unittest.cc

Issue 1573013002: Fix a race in HandleWatcherTest and remove suppression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/sanitizers/tsan_suppressions.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/message_pump/handle_watcher_unittest.cc
diff --git a/mojo/message_pump/handle_watcher_unittest.cc b/mojo/message_pump/handle_watcher_unittest.cc
index 14c1851202f3682dcabef1076d072b40969e5b54..c076587d6913ac3837bb854c347e8a87b18ac357 100644
--- a/mojo/message_pump/handle_watcher_unittest.cc
+++ b/mojo/message_pump/handle_watcher_unittest.cc
@@ -10,6 +10,7 @@
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/run_loop.h"
#include "base/test/simple_test_tick_clock.h"
@@ -121,8 +122,14 @@ class CallbackHelper {
class HandleWatcherTest : public testing::TestWithParam<MessageLoopConfig> {
public:
- HandleWatcherTest() : message_loop_(CreateMessageLoop(GetParam())) {}
+ HandleWatcherTest()
+ : at_exit_(new base::ShadowingAtExitManager),
+ message_loop_(CreateMessageLoop(GetParam())) {}
virtual ~HandleWatcherTest() {
+ // By explicitly destroying |at_exit_| before resetting the tick clock, it
+ // ensures that the handle watcher thread (if there is one) is shut down,
+ // preventing a race with users of the tick clock in MessagePumpMojo.
+ at_exit_.reset();
test::SetTickClockForTest(NULL);
}
@@ -131,6 +138,8 @@ class HandleWatcherTest : public testing::TestWithParam<MessageLoopConfig> {
message_loop_.reset();
}
+ // This should be called at the beginning of any test that needs it, so that
+ // it is installed before the handle watcher thread starts.
void InstallTickClock() {
test::SetTickClockForTest(&tick_clock_);
}
@@ -138,7 +147,7 @@ class HandleWatcherTest : public testing::TestWithParam<MessageLoopConfig> {
base::SimpleTestTickClock tick_clock_;
private:
- base::ShadowingAtExitManager at_exit_;
+ scoped_ptr<base::ShadowingAtExitManager> at_exit_;
scoped_ptr<base::MessageLoop> message_loop_;
DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest);
« no previous file with comments | « build/sanitizers/tsan_suppressions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698