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

Unified Diff: net/log/bounded_file_net_log_observer_unittest.cc

Issue 2567473003: Reduce the number of PostTasks done by BoundedFiledNetLog. (Closed)
Patch Set: Created 4 years 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 | « net/log/bounded_file_net_log_observer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/log/bounded_file_net_log_observer_unittest.cc
diff --git a/net/log/bounded_file_net_log_observer_unittest.cc b/net/log/bounded_file_net_log_observer_unittest.cc
index 7e0ee9c8553e9adce008bd97baadbcde16b72740..4e1aeb8de8f1bdb2407402678573e04c50a6bf5e 100644
--- a/net/log/bounded_file_net_log_observer_unittest.cc
+++ b/net/log/bounded_file_net_log_observer_unittest.cc
@@ -792,6 +792,48 @@ TEST_F(BoundedFileNetLogObserverTest,
ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info));
}
+// Adds events concurrently from several different threads. The exact order of
+// events seen by this test is non-deterministic.
+TEST_F(BoundedFileNetLogObserverTest, AddEventsFromMultipleThreads) {
+ const size_t kNumThreads = 10;
+ std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads);
+ // Start all the threads. Waiting for them to start is to hopefuly improve
+ // the odds of hitting interesting races once events start being added.
+ for (size_t i = 0; i < threads.size(); ++i) {
+ threads[i] = base::MakeUnique<base::Thread>(
+ base::StringPrintf("WorkerThread%i", static_cast<int>(i)));
+ threads[i]->Start();
+ threads[i]->WaitUntilThreadStarted();
+ }
+
+ logger_->StartObserving(&net_log_, log_path_, nullptr, nullptr,
+ kLargeFileSize, kTotalNumFiles);
+
+ const size_t kNumEventsAddedPerThread = 200;
+
+ // Add events in parallel from all the threads.
+ for (size_t i = 0; i < kNumThreads; ++i) {
+ threads[i]->task_runner()->PostTask(
+ FROM_HERE, base::Bind(&BoundedFileNetLogObserverTest::AddEntries,
+ base::Unretained(this), kNumEventsAddedPerThread,
+ kDummyEventSize));
+ }
+
+ // Join all the threads.
+ threads.clear();
+
+ // Stop observing.
+ TestClosure closure;
+ logger_->StopObserving(nullptr, closure.closure());
+ closure.WaitForResult();
+
+ // Check that the expected number of events were written to disk.
+ std::unique_ptr<base::Value> root;
+ base::ListValue* events;
+ ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
+ ASSERT_EQ(kNumEventsAddedPerThread * kNumThreads, events->GetSize());
+}
+
} // namespace
} // namespace net
« no previous file with comments | « net/log/bounded_file_net_log_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698