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

Unified Diff: base/threading/simple_thread_unittest.cc

Issue 2218983003: Force non-joinable SimpleThreads to be leaked. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f1_eatsecondparam_expectdcheckdeath
Patch Set: Created 4 years, 4 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 | « base/threading/simple_thread.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/simple_thread_unittest.cc
diff --git a/base/threading/simple_thread_unittest.cc b/base/threading/simple_thread_unittest.cc
index 26e3a907bc7b5faed77525e59f0a758fabc0472f..8b197a89238f728d7d83f1e1986b9d3f7f9982d8 100644
--- a/base/threading/simple_thread_unittest.cc
+++ b/base/threading/simple_thread_unittest.cc
@@ -5,6 +5,7 @@
#include <memory>
#include "base/atomic_sequence_num.h"
+#include "base/debug/leak_annotations.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/gtest_util.h"
@@ -146,23 +147,34 @@ TEST(SimpleThreadTest, NamedWithOptions) {
std::string("event_waiter/") + IntToString(thread.tid()));
}
-TEST(SimpleThreadTest, JoinNonJoinableThreadDeath) {
+TEST(SimpleThreadTest, StartNonJoinableThreadAndDieOnJoin) {
SleepRunner runner;
sdefresne 2016/08/05 16:48:33 I think SleepRunner also needs to be leaked as Del
gab 2016/08/05 17:28:33 Good point, for DelegateSimpleThread, the Delegate
+
SimpleThread::Options options;
options.joinable = false;
- DelegateSimpleThread thread(&runner, "noop_runner", options);
+ DelegateSimpleThread* thread =
+ new DelegateSimpleThread(&runner, "noop_runner", options);
+ // Non-joinable SimpleThreads have to be leaked.
+ ANNOTATE_LEAKING_OBJECT_PTR(thread);
- thread.Start();
- EXPECT_DCHECK_DEATH(thread.Join());
+ EXPECT_FALSE(thread->HasBeenStarted());
+ thread->Start();
+ EXPECT_TRUE(thread->HasBeenStarted());
+ EXPECT_FALSE(thread->HasBeenJoined());
+
+ EXPECT_DCHECK_DEATH(thread->Join());
}
-TEST(SimpleThreadTest, DeleteNonJoinableWithoutJoinIsSafe) {
+TEST(SimpleThreadTest, NonJoinableThreadDeathOnDestruction) {
SleepRunner runner;
SimpleThread::Options options;
options.joinable = false;
- DelegateSimpleThread thread(&runner, "noop_runner", options);
- thread.Start();
- // Nothing blows up when |thread| goes out of scope.
+ DelegateSimpleThread* thread =
+ new DelegateSimpleThread(&runner, "noop_runner", options);
+ ANNOTATE_LEAKING_OBJECT_PTR(thread);
+
+ thread->Start();
+ EXPECT_DCHECK_DEATH({ delete thread; });
}
TEST(SimpleThreadTest, ThreadPool) {
« no previous file with comments | « base/threading/simple_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698