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

Unified Diff: base/tracked_objects_unittest.cc

Issue 2488073002: Reuse ThreadData instances associated with terminated named threads. (Closed)
Patch Set: CR danakj #55 (nits) Created 4 years, 1 month 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
Index: base/tracked_objects_unittest.cc
diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc
index 70d9601cd0f9be78570cabab1ce23d7b6413917e..20f57b370cd8b3c811d500443a43ff91991d1e25 100644
--- a/base/tracked_objects_unittest.cc
+++ b/base/tracked_objects_unittest.cc
@@ -11,14 +11,17 @@
#include <memory>
+#include "base/macros.h"
#include "base/process/process_handle.h"
+#include "base/strings/stringprintf.h"
+#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/tracking_info.h"
#include "testing/gtest/include/gtest/gtest.h"
const int kLineNumber = 1776;
const char kFile[] = "FixedUnitTestFileName";
-const char kWorkerThreadName[] = "WorkerThread-1";
+const char kWorkerThreadName[] = "WorkerThread-*";
const char kMainThreadName[] = "SomeMainThreadName";
const char kStillAlive[] = "Still_Alive";
@@ -108,6 +111,16 @@ class TrackedObjectsTest : public testing::Test {
// Sets time that will be returned by ThreadData::Now().
static void SetTestTime(unsigned int test_time) { test_time_ = test_time; }
+ int GetNumThreadData() {
Nico 2016/11/24 01:42:04 doesn't this have to take the list lock?
fdoray 2016/11/29 16:10:33 No. ThreadData::first() takes a lock. The list can
+ int num_thread_data = 0;
+ ThreadData* current = ThreadData::first();
+ while (current) {
+ ++num_thread_data;
+ current = current->next();
+ }
+ return num_thread_data;
+ }
+
private:
// Returns test time in milliseconds.
static unsigned int GetTestTime() { return test_time_; }
@@ -1184,4 +1197,25 @@ TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
}
+// Repetitively create and stop named threads. Verify that the number of
+// instantiated ThreadData instance is equal to the number of different
+// sanitized thread names used in the test.
+TEST_F(TrackedObjectsTest, ReuseRetiredThreadData) {
+ const char* const kThreadNames[] = {"Foo%d", "Bar%d", "123Dummy%d",
+ "456Dummy%d"};
Nico 2016/11/24 01:42:04 include a thread that has only digits in the name
fdoray 2016/11/29 16:10:33 Done.
+ constexpr int kNumIterations = 10;
+ EXPECT_EQ(0, GetNumThreadData());
+
+ for (int i = 0; i < kNumIterations; ++i) {
+ for (const char* thread_name : kThreadNames) {
+ base::Thread thread(base::StringPrintf(thread_name, i));
+ EXPECT_TRUE(thread.Start());
+ }
+ }
+
+ // Expect one ThreadData instance for each element in |kThreadNames| and one
+ // ThreadData instance for the main thread.
+ EXPECT_EQ(static_cast<int>(arraysize(kThreadNames) + 1), GetNumThreadData());
+}
+
} // namespace tracked_objects

Powered by Google App Engine
This is Rietveld 408576698