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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « net/log/bounded_file_net_log_observer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/log/bounded_file_net_log_observer.h" 5 #include "net/log/bounded_file_net_log_observer.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // Check that 1 event was written 785 // Check that 1 event was written
786 ASSERT_EQ(1u, events->GetSize()); 786 ASSERT_EQ(1u, events->GetSize());
787 787
788 // Make sure additional information is present, but don't validate it. 788 // Make sure additional information is present, but don't validate it.
789 base::DictionaryValue* dict; 789 base::DictionaryValue* dict;
790 ASSERT_TRUE(root->GetAsDictionary(&dict)); 790 ASSERT_TRUE(root->GetAsDictionary(&dict));
791 base::DictionaryValue* tab_info; 791 base::DictionaryValue* tab_info;
792 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); 792 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info));
793 } 793 }
794 794
795 // Adds events concurrently from several different threads. The exact order of
796 // events seen by this test is non-deterministic.
797 TEST_F(BoundedFileNetLogObserverTest, AddEventsFromMultipleThreads) {
798 const size_t kNumThreads = 10;
799 std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads);
800 // Start all the threads. Waiting for them to start is to hopefuly improve
801 // the odds of hitting interesting races once events start being added.
802 for (size_t i = 0; i < threads.size(); ++i) {
803 threads[i] = base::MakeUnique<base::Thread>(
804 base::StringPrintf("WorkerThread%i", static_cast<int>(i)));
805 threads[i]->Start();
806 threads[i]->WaitUntilThreadStarted();
807 }
808
809 logger_->StartObserving(&net_log_, log_path_, nullptr, nullptr,
810 kLargeFileSize, kTotalNumFiles);
811
812 const size_t kNumEventsAddedPerThread = 200;
813
814 // Add events in parallel from all the threads.
815 for (size_t i = 0; i < kNumThreads; ++i) {
816 threads[i]->task_runner()->PostTask(
817 FROM_HERE, base::Bind(&BoundedFileNetLogObserverTest::AddEntries,
818 base::Unretained(this), kNumEventsAddedPerThread,
819 kDummyEventSize));
820 }
821
822 // Join all the threads.
823 threads.clear();
824
825 // Stop observing.
826 TestClosure closure;
827 logger_->StopObserving(nullptr, closure.closure());
828 closure.WaitForResult();
829
830 // Check that the expected number of events were written to disk.
831 std::unique_ptr<base::Value> root;
832 base::ListValue* events;
833 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
834 ASSERT_EQ(kNumEventsAddedPerThread * kNumThreads, events->GetSize());
835 }
836
795 } // namespace 837 } // namespace
796 838
797 } // namespace net 839 } // namespace net
OLDNEW
« 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