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

Side by Side Diff: net/log/file_net_log_observer_unittest.cc

Issue 2698143004: Add ongoing events to net-export log when logging starts (Closed)
Patch Set: Fixed Eric's comments from ps10 Created 3 years, 9 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 unified diff | Download patch
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/file_net_log_observer.h" 5 #include "net/log/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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 class FileNetLogObserverTest : public ::testing::TestWithParam<bool> { 155 class FileNetLogObserverTest : public ::testing::TestWithParam<bool> {
156 public: 156 public:
157 void SetUp() override { 157 void SetUp() override {
158 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 158 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
159 bounded_log_dir_ = temp_dir_.GetPath(); 159 bounded_log_dir_ = temp_dir_.GetPath();
160 unbounded_log_path_ = bounded_log_dir_.AppendASCII("net-log.json"); 160 unbounded_log_path_ = bounded_log_dir_.AppendASCII("net-log.json");
161 file_thread_.reset(new base::Thread("NetLog File Thread")); 161 file_thread_.reset(new base::Thread("NetLog File Thread"));
162 file_thread_->StartWithOptions( 162 file_thread_->StartWithOptions(
163 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); 163 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0));
164 ASSERT_TRUE(file_thread_->WaitUntilThreadStarted()); 164 ASSERT_TRUE(file_thread_->WaitUntilThreadStarted());
165 logger_.reset(new FileNetLogObserver(file_thread_->task_runner()));
166 } 165 }
167 166
168 void StartObserving(std::unique_ptr<base::Value> constants, 167 void CreateAndStartObserving(std::unique_ptr<base::Value> constants) {
169 URLRequestContext* url_request_context) {
170 bool bounded = GetParam(); 168 bool bounded = GetParam();
171 if (bounded) { 169 if (bounded) {
172 logger_->StartObservingBounded(&net_log_, NetLogCaptureMode::Default(), 170 logger_ = FileNetLogObserver::CreateBounded(
173 bounded_log_dir_, std::move(constants), 171 file_thread_->task_runner(), bounded_log_dir_, kLargeFileSize,
174 url_request_context, kLargeFileSize, 172 kTotalNumFiles, std::move(constants));
175 kTotalNumFiles);
176 } else { 173 } else {
177 logger_->StartObservingUnbounded( 174 logger_ = FileNetLogObserver::CreateUnbounded(file_thread_->task_runner(),
178 &net_log_, NetLogCaptureMode::Default(), unbounded_log_path_, 175 unbounded_log_path_,
179 std::move(constants), url_request_context); 176 std::move(constants));
180 } 177 }
178
179 logger_->StartObserving(&net_log_, NetLogCaptureMode::Default());
181 } 180 }
182 181
183 ::testing::AssertionResult ReadNetLogFromDisk( 182 ::testing::AssertionResult ReadNetLogFromDisk(
184 std::unique_ptr<base::Value>* root, 183 std::unique_ptr<base::Value>* root,
185 base::ListValue** events) { 184 base::ListValue** events) {
186 bool bounded = GetParam(); 185 bool bounded = GetParam();
187 std::string input; 186 std::string input;
188 if (bounded) { 187 if (bounded) {
189 ReadBoundedLogFiles(bounded_log_dir_, &input); 188 ReadBoundedLogFiles(bounded_log_dir_, &input);
190 } else { 189 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Used for tests that are exclusive to the bounded mode of FileNetLogObserver. 223 // Used for tests that are exclusive to the bounded mode of FileNetLogObserver.
225 class FileNetLogObserverBoundedTest : public ::testing::Test { 224 class FileNetLogObserverBoundedTest : public ::testing::Test {
226 public: 225 public:
227 void SetUp() override { 226 void SetUp() override {
228 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 227 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
229 bounded_log_dir_ = temp_dir_.GetPath(); 228 bounded_log_dir_ = temp_dir_.GetPath();
230 file_thread_.reset(new base::Thread("NetLog File Thread")); 229 file_thread_.reset(new base::Thread("NetLog File Thread"));
231 file_thread_->StartWithOptions( 230 file_thread_->StartWithOptions(
232 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); 231 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0));
233 ASSERT_TRUE(file_thread_->WaitUntilThreadStarted()); 232 ASSERT_TRUE(file_thread_->WaitUntilThreadStarted());
234 logger_.reset(new FileNetLogObserver(file_thread_->task_runner()));
235 } 233 }
236 234
237 void StartObserving(std::unique_ptr<base::Value> constants, 235 void CreateAndStartObserving(std::unique_ptr<base::Value> constants,
238 URLRequestContext* url_request_context, 236 int total_file_size,
239 int total_file_size, 237 int num_files) {
240 int num_files) { 238 logger_ = FileNetLogObserver::CreateBounded(
241 logger_->StartObservingBounded( 239 file_thread_->task_runner(), bounded_log_dir_, total_file_size,
242 &net_log_, NetLogCaptureMode::Default(), bounded_log_dir_, 240 num_files, std::move(constants));
243 std::move(constants), url_request_context, total_file_size, num_files); 241 logger_->StartObserving(&net_log_, NetLogCaptureMode::Default());
244 } 242 }
245 243
246 ::testing::AssertionResult ReadNetLogFromDisk( 244 ::testing::AssertionResult ReadNetLogFromDisk(
247 std::unique_ptr<base::Value>* root, 245 std::unique_ptr<base::Value>* root,
248 base::ListValue** events) { 246 base::ListValue** events) {
249 std::string input; 247 std::string input;
250 ReadBoundedLogFiles(bounded_log_dir_, &input); 248 ReadBoundedLogFiles(bounded_log_dir_, &input);
251 return ParseNetLogString(input, root, events); 249 return ParseNetLogString(input, root, events);
252 } 250 }
253 251
(...skipping 17 matching lines...) Expand all
271 base::ScopedTempDir temp_dir_; 269 base::ScopedTempDir temp_dir_;
272 base::FilePath bounded_log_dir_; 270 base::FilePath bounded_log_dir_;
273 }; 271 };
274 272
275 // Instantiates each FileNetLogObserverTest to use bounded and unbounded modes. 273 // Instantiates each FileNetLogObserverTest to use bounded and unbounded modes.
276 INSTANTIATE_TEST_CASE_P(, 274 INSTANTIATE_TEST_CASE_P(,
277 FileNetLogObserverTest, 275 FileNetLogObserverTest,
278 ::testing::Values(true, false)); 276 ::testing::Values(true, false));
279 277
280 TEST_P(FileNetLogObserverTest, ObserverDestroyedWithoutStopObserving) { 278 TEST_P(FileNetLogObserverTest, ObserverDestroyedWithoutStopObserving) {
281 StartObserving(nullptr, nullptr); 279 CreateAndStartObserving(nullptr);
282 280
283 // Send dummy event 281 // Send dummy event
284 AddEntries(logger_.get(), 1, kDummyEventSize); 282 AddEntries(logger_.get(), 1, kDummyEventSize);
285 283
286 logger_.reset(); 284 logger_.reset();
287 file_thread_.reset(); 285 file_thread_.reset();
288 286
289 ASSERT_FALSE(LogFilesExist()); 287 ASSERT_FALSE(LogFilesExist());
290 } 288 }
291 289
292 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithNoEvents) { 290 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithNoEvents) {
293 TestClosure closure; 291 TestClosure closure;
294 292
295 StartObserving(nullptr, nullptr); 293 CreateAndStartObserving(nullptr);
296 294
297 logger_->StopObserving(nullptr, closure.closure()); 295 logger_->StopObserving(nullptr, closure.closure());
298 296
299 closure.WaitForResult(); 297 closure.WaitForResult();
300 298
301 std::unique_ptr<base::Value> root; 299 std::unique_ptr<base::Value> root;
302 base::ListValue* events; 300 base::ListValue* events;
303 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 301 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
304 302
305 // Check that there are no events 303 // Check that there are no events
306 ASSERT_EQ(0u, events->GetSize()); 304 ASSERT_EQ(0u, events->GetSize());
307 305
308 // Check that constants are printed 306 // Check that constants are printed
309 base::DictionaryValue* dict; 307 base::DictionaryValue* dict;
310 ASSERT_TRUE(root->GetAsDictionary(&dict)); 308 ASSERT_TRUE(root->GetAsDictionary(&dict));
311 base::DictionaryValue* constants; 309 base::DictionaryValue* constants;
312 ASSERT_TRUE(dict->GetDictionary("constants", &constants)); 310 ASSERT_TRUE(dict->GetDictionary("constants", &constants));
313 } 311 }
314 312
315 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { 313 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) {
316 TestClosure closure; 314 TestClosure closure;
317 315
318 StartObserving(nullptr, nullptr); 316 CreateAndStartObserving(nullptr);
319 317
320 // Send dummy event. 318 // Send dummy event.
321 AddEntries(logger_.get(), 1, kDummyEventSize); 319 AddEntries(logger_.get(), 1, kDummyEventSize);
322 320
323 logger_->StopObserving(nullptr, closure.closure()); 321 logger_->StopObserving(nullptr, closure.closure());
324 322
325 closure.WaitForResult(); 323 closure.WaitForResult();
326 324
327 std::unique_ptr<base::Value> root; 325 std::unique_ptr<base::Value> root;
328 base::ListValue* events; 326 base::ListValue* events;
329 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 327 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
330 328
331 // Check that there is 1 event written. 329 // Check that there is 1 event written.
332 ASSERT_EQ(1u, events->GetSize()); 330 ASSERT_EQ(1u, events->GetSize());
333 } 331 }
334 332
335 TEST_P(FileNetLogObserverTest, CustomConstants) { 333 TEST_P(FileNetLogObserverTest, CustomConstants) {
336 TestClosure closure; 334 TestClosure closure;
337 335
338 const char kConstantString[] = "awesome constant"; 336 const char kConstantString[] = "awesome constant";
339 std::unique_ptr<base::Value> constants( 337 std::unique_ptr<base::Value> constants(
340 new base::StringValue(kConstantString)); 338 new base::StringValue(kConstantString));
341 339
342 StartObserving(std::move(constants), nullptr); 340 CreateAndStartObserving(std::move(constants));
343 341
344 logger_->StopObserving(nullptr, closure.closure()); 342 logger_->StopObserving(nullptr, closure.closure());
345 343
346 closure.WaitForResult(); 344 closure.WaitForResult();
347 345
348 std::unique_ptr<base::Value> root; 346 std::unique_ptr<base::Value> root;
349 base::ListValue* events; 347 base::ListValue* events;
350 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 348 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
351 349
352 // Check that custom constant was correctly printed. 350 // Check that custom constant was correctly printed.
353 base::DictionaryValue* dict; 351 base::DictionaryValue* dict;
354 ASSERT_TRUE(root->GetAsDictionary(&dict)); 352 ASSERT_TRUE(root->GetAsDictionary(&dict));
355 std::string constants_string; 353 std::string constants_string;
356 ASSERT_TRUE(dict->GetString("constants", &constants_string)); 354 ASSERT_TRUE(dict->GetString("constants", &constants_string));
357 ASSERT_EQ(kConstantString, constants_string); 355 ASSERT_EQ(kConstantString, constants_string);
358 } 356 }
359 357
360 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) { 358 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) {
361 TestClosure closure; 359 TestClosure closure;
362 360
363 StartObserving(nullptr, nullptr); 361 CreateAndStartObserving(nullptr);
364 362
365 // Create dummy polled data 363 // Create dummy polled data
366 const char kDummyPolledDataPath[] = "dummy_path"; 364 const char kDummyPolledDataPath[] = "dummy_path";
367 const char kDummyPolledDataString[] = "dummy_info"; 365 const char kDummyPolledDataString[] = "dummy_info";
368 std::unique_ptr<base::DictionaryValue> dummy_polled_data = 366 std::unique_ptr<base::DictionaryValue> dummy_polled_data =
369 base::MakeUnique<base::DictionaryValue>(); 367 base::MakeUnique<base::DictionaryValue>();
370 dummy_polled_data->SetString(kDummyPolledDataPath, kDummyPolledDataString); 368 dummy_polled_data->SetString(kDummyPolledDataPath, kDummyPolledDataString);
371 369
372 logger_->StopObserving(std::move(dummy_polled_data), closure.closure()); 370 logger_->StopObserving(std::move(dummy_polled_data), closure.closure());
373 371
374 closure.WaitForResult(); 372 closure.WaitForResult();
375 373
376 std::unique_ptr<base::Value> root; 374 std::unique_ptr<base::Value> root;
377 base::ListValue* events; 375 base::ListValue* events;
378 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 376 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
379 377
380 // Check that no events were written. 378 // Check that no events were written.
381 ASSERT_EQ(0u, events->GetSize()); 379 ASSERT_EQ(0u, events->GetSize());
382 380
383 // Make sure additional information is present and validate it. 381 // Make sure additional information is present and validate it.
384 base::DictionaryValue* dict; 382 base::DictionaryValue* dict;
385 ASSERT_TRUE(root->GetAsDictionary(&dict)); 383 ASSERT_TRUE(root->GetAsDictionary(&dict));
386 base::DictionaryValue* polled_data; 384 base::DictionaryValue* polled_data;
387 std::string dummy_string; 385 std::string dummy_string;
388 ASSERT_TRUE(dict->GetDictionary("polledData", &polled_data)); 386 ASSERT_TRUE(dict->GetDictionary("polledData", &polled_data));
389 ASSERT_TRUE(polled_data->GetString(kDummyPolledDataPath, &dummy_string)); 387 ASSERT_TRUE(polled_data->GetString(kDummyPolledDataPath, &dummy_string));
390 ASSERT_EQ(dummy_string, kDummyPolledDataString); 388 ASSERT_EQ(dummy_string, kDummyPolledDataString);
391 } 389 }
392 390
393 TEST_P(FileNetLogObserverTest,
394 GeneratesValidJSONWithPolledDataWithActiveRequest) {
395 TestClosure closure;
396
397 // Create context, start a request.
398 TestURLRequestContext context(true);
399 context.set_net_log(&net_log_);
400 context.Init();
401 TestDelegate delegate;
402 delegate.set_quit_on_complete(false);
403
404 // URL doesn't matter. Requests can't fail synchronously.
405 std::unique_ptr<URLRequest> request(
406 context.CreateRequest(GURL("blah:blah"), IDLE, &delegate));
407 request->Start();
408
409 StartObserving(nullptr, &context);
410
411 logger_->StopObserving(net::GetNetInfo(&context, NET_INFO_ALL_SOURCES),
412 closure.closure());
413
414 closure.WaitForResult();
415
416 std::unique_ptr<base::Value> root;
417 base::ListValue* events;
418 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
419
420 // Check that 1 event was written
421 ASSERT_EQ(1u, events->GetSize());
422
423 // Make sure additional information is present, but don't validate it.
424 base::DictionaryValue* dict;
425 ASSERT_TRUE(root->GetAsDictionary(&dict));
426 base::DictionaryValue* polled_data;
427 ASSERT_TRUE(dict->GetDictionary("polledData", &polled_data));
428 }
429
430 // Adds events concurrently from several different threads. The exact order of 391 // Adds events concurrently from several different threads. The exact order of
431 // events seen by this test is non-deterministic. 392 // events seen by this test is non-deterministic.
432 TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) { 393 TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) {
433 const size_t kNumThreads = 10; 394 const size_t kNumThreads = 10;
434 std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads); 395 std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads);
435 // Start all the threads. Waiting for them to start is to hopefuly improve 396 // Start all the threads. Waiting for them to start is to hopefuly improve
436 // the odds of hitting interesting races once events start being added. 397 // the odds of hitting interesting races once events start being added.
437 for (size_t i = 0; i < threads.size(); ++i) { 398 for (size_t i = 0; i < threads.size(); ++i) {
438 threads[i] = base::MakeUnique<base::Thread>( 399 threads[i] = base::MakeUnique<base::Thread>(
439 base::StringPrintf("WorkerThread%i", static_cast<int>(i))); 400 base::StringPrintf("WorkerThread%i", static_cast<int>(i)));
440 threads[i]->Start(); 401 threads[i]->Start();
441 threads[i]->WaitUntilThreadStarted(); 402 threads[i]->WaitUntilThreadStarted();
442 } 403 }
443 404
444 StartObserving(nullptr, nullptr); 405 CreateAndStartObserving(nullptr);
445 406
446 const size_t kNumEventsAddedPerThread = 200; 407 const size_t kNumEventsAddedPerThread = 200;
447 408
448 // Add events in parallel from all the threads. 409 // Add events in parallel from all the threads.
449 for (size_t i = 0; i < kNumThreads; ++i) { 410 for (size_t i = 0; i < kNumThreads; ++i) {
450 threads[i]->task_runner()->PostTask( 411 threads[i]->task_runner()->PostTask(
451 FROM_HERE, base::Bind(&AddEntries, base::Unretained(logger_.get()), 412 FROM_HERE, base::Bind(&AddEntries, base::Unretained(logger_.get()),
452 kNumEventsAddedPerThread, kDummyEventSize)); 413 kNumEventsAddedPerThread, kDummyEventSize));
453 } 414 }
454 415
(...skipping 15 matching lines...) Expand all
470 // Sends enough events to the observer to completely fill one file, but not 431 // Sends enough events to the observer to completely fill one file, but not
471 // write any events to an additional file. Checks the file bounds. 432 // write any events to an additional file. Checks the file bounds.
472 TEST_F(FileNetLogObserverBoundedTest, EqualToOneFile) { 433 TEST_F(FileNetLogObserverBoundedTest, EqualToOneFile) {
473 // The total size of the events is equal to the size of one file. 434 // The total size of the events is equal to the size of one file.
474 // |kNumEvents| * |kEventSize| = |kTotalFileSize| / |kTotalNumEvents| 435 // |kNumEvents| * |kEventSize| = |kTotalFileSize| / |kTotalNumEvents|
475 const int kTotalFileSize = 5000; 436 const int kTotalFileSize = 5000;
476 const int kNumEvents = 2; 437 const int kNumEvents = 2;
477 const int kEventSize = 250; 438 const int kEventSize = 250;
478 TestClosure closure; 439 TestClosure closure;
479 440
480 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 441 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
481 442
482 AddEntries(logger_.get(), kNumEvents, kEventSize); 443 AddEntries(logger_.get(), kNumEvents, kEventSize);
483 logger_->StopObserving(nullptr, closure.closure()); 444 logger_->StopObserving(nullptr, closure.closure());
484 445
485 closure.WaitForResult(); 446 closure.WaitForResult();
486 447
487 std::unique_ptr<base::Value> root; 448 std::unique_ptr<base::Value> root;
488 base::ListValue* events; 449 base::ListValue* events;
489 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 450 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
490 451
(...skipping 26 matching lines...) Expand all
517 // The total size of the events is greater than the size of one file, and 478 // The total size of the events is greater than the size of one file, and
518 // less than the size of two files. The total size of all events except one 479 // less than the size of two files. The total size of all events except one
519 // is equal to the size of one file, so the last event will be the only event 480 // is equal to the size of one file, so the last event will be the only event
520 // in the second file. 481 // in the second file.
521 // (|kNumEvents| - 1) * kEventSize = |kTotalFileSize| / |kTotalNumEvents| 482 // (|kNumEvents| - 1) * kEventSize = |kTotalFileSize| / |kTotalNumEvents|
522 const int kTotalFileSize = 6000; 483 const int kTotalFileSize = 6000;
523 const int kNumEvents = 4; 484 const int kNumEvents = 4;
524 const int kEventSize = 200; 485 const int kEventSize = 200;
525 TestClosure closure; 486 TestClosure closure;
526 487
527 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 488 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
528 489
529 AddEntries(logger_.get(), kNumEvents, kEventSize); 490 AddEntries(logger_.get(), kNumEvents, kEventSize);
530 491
531 logger_->StopObserving(nullptr, closure.closure()); 492 logger_->StopObserving(nullptr, closure.closure());
532 493
533 closure.WaitForResult(); 494 closure.WaitForResult();
534 495
535 std::unique_ptr<base::Value> root; 496 std::unique_ptr<base::Value> root;
536 base::ListValue* events; 497 base::ListValue* events;
537 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 498 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 20 matching lines...) Expand all
558 519
559 // Sends enough events to the observer to completely fill two files. 520 // Sends enough events to the observer to completely fill two files.
560 TEST_F(FileNetLogObserverBoundedTest, EqualToTwoFiles) { 521 TEST_F(FileNetLogObserverBoundedTest, EqualToTwoFiles) {
561 // The total size of the events is equal to the total size of two files. 522 // The total size of the events is equal to the total size of two files.
562 // |kNumEvents| * |kEventSize| = 2 * |kTotalFileSize| / |kTotalNumEvents| 523 // |kNumEvents| * |kEventSize| = 2 * |kTotalFileSize| / |kTotalNumEvents|
563 const int kTotalFileSize = 6000; 524 const int kTotalFileSize = 6000;
564 const int kNumEvents = 6; 525 const int kNumEvents = 6;
565 const int kEventSize = 200; 526 const int kEventSize = 200;
566 TestClosure closure; 527 TestClosure closure;
567 528
568 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 529 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
569 530
570 AddEntries(logger_.get(), kNumEvents, kEventSize); 531 AddEntries(logger_.get(), kNumEvents, kEventSize);
571 532
572 logger_->StopObserving(nullptr, closure.closure()); 533 logger_->StopObserving(nullptr, closure.closure());
573 534
574 closure.WaitForResult(); 535 closure.WaitForResult();
575 536
576 std::unique_ptr<base::Value> root; 537 std::unique_ptr<base::Value> root;
577 base::ListValue* events; 538 base::ListValue* events;
578 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 539 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // overwritten. 571 // overwritten.
611 TEST_F(FileNetLogObserverBoundedTest, FillAllFilesNoOverwriting) { 572 TEST_F(FileNetLogObserverBoundedTest, FillAllFilesNoOverwriting) {
612 // The total size of events is equal to the total size of all files. 573 // The total size of events is equal to the total size of all files.
613 // |kEventSize| * |kNumEvents| = |kTotalFileSize| 574 // |kEventSize| * |kNumEvents| = |kTotalFileSize|
614 const int kTotalFileSize = 10000; 575 const int kTotalFileSize = 10000;
615 const int kEventSize = 200; 576 const int kEventSize = 200;
616 const int kFileSize = kTotalFileSize / kTotalNumFiles; 577 const int kFileSize = kTotalFileSize / kTotalNumFiles;
617 const int kNumEvents = kTotalNumFiles * ((kFileSize - 1) / kEventSize + 1); 578 const int kNumEvents = kTotalNumFiles * ((kFileSize - 1) / kEventSize + 1);
618 TestClosure closure; 579 TestClosure closure;
619 580
620 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 581 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
621 582
622 AddEntries(logger_.get(), kNumEvents, kEventSize); 583 AddEntries(logger_.get(), kNumEvents, kEventSize);
623 584
624 logger_->StopObserving(nullptr, closure.closure()); 585 logger_->StopObserving(nullptr, closure.closure());
625 586
626 closure.WaitForResult(); 587 closure.WaitForResult();
627 588
628 std::unique_ptr<base::Value> root; 589 std::unique_ptr<base::Value> root;
629 base::ListValue* events; 590 base::ListValue* events;
630 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 591 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 25 matching lines...) Expand all
656 // The total size of events is greater than the WriteQueue's memory limit, so 617 // The total size of events is greater than the WriteQueue's memory limit, so
657 // the oldest event must be dropped from the queue and not written to any 618 // the oldest event must be dropped from the queue and not written to any
658 // file. 619 // file.
659 // |kNumEvents| * |kEventSize| > |kTotalFileSize| * 2 620 // |kNumEvents| * |kEventSize| > |kTotalFileSize| * 2
660 const int kTotalFileSize = 1000; 621 const int kTotalFileSize = 1000;
661 const int kNumEvents = 11; 622 const int kNumEvents = 11;
662 const int kEventSize = 200; 623 const int kEventSize = 200;
663 const int kFileSize = kTotalFileSize / kTotalNumFiles; 624 const int kFileSize = kTotalFileSize / kTotalNumFiles;
664 TestClosure closure; 625 TestClosure closure;
665 626
666 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 627 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
667 628
668 AddEntries(logger_.get(), kNumEvents, kEventSize); 629 AddEntries(logger_.get(), kNumEvents, kEventSize);
669 630
670 logger_->StopObserving(nullptr, closure.closure()); 631 logger_->StopObserving(nullptr, closure.closure());
671 632
672 closure.WaitForResult(); 633 closure.WaitForResult();
673 634
674 std::unique_ptr<base::Value> root; 635 std::unique_ptr<base::Value> root;
675 base::ListValue* events; 636 base::ListValue* events;
676 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 637 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 30 matching lines...) Expand all
707 // The total size of the events is much greater than twice the number of 668 // The total size of the events is much greater than twice the number of
708 // events that can fit in the event files, to make sure that the extra events 669 // events that can fit in the event files, to make sure that the extra events
709 // are written to a file, not just dropped from the queue. 670 // are written to a file, not just dropped from the queue.
710 // |kNumEvents| * |kEventSize| >= 2 * |kTotalFileSize| 671 // |kNumEvents| * |kEventSize| >= 2 * |kTotalFileSize|
711 const int kTotalFileSize = 6000; 672 const int kTotalFileSize = 6000;
712 const int kNumEvents = 60; 673 const int kNumEvents = 60;
713 const int kEventSize = 200; 674 const int kEventSize = 200;
714 const int kFileSize = kTotalFileSize / kTotalNumFiles; 675 const int kFileSize = kTotalFileSize / kTotalNumFiles;
715 TestClosure closure; 676 TestClosure closure;
716 677
717 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 678 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
718 679
719 AddEntries(logger_.get(), kNumEvents, kEventSize); 680 AddEntries(logger_.get(), kNumEvents, kEventSize);
720 681
721 logger_->StopObserving(nullptr, closure.closure()); 682 logger_->StopObserving(nullptr, closure.closure());
722 683
723 closure.WaitForResult(); 684 closure.WaitForResult();
724 685
725 std::unique_ptr<base::Value> root; 686 std::unique_ptr<base::Value> root;
726 base::ListValue* events; 687 base::ListValue* events;
727 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 688 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // than twice the number of event files, so not every file will need to be 740 // than twice the number of event files, so not every file will need to be
780 // overwritten. 741 // overwritten.
781 // |kTotalFileSize| < |kNumEvents| * |kEventSize| 742 // |kTotalFileSize| < |kNumEvents| * |kEventSize|
782 // |kNumEvents| * |kEventSize| <= (2 * |kTotalNumFiles| - 1) * |kFileSize| 743 // |kNumEvents| * |kEventSize| <= (2 * |kTotalNumFiles| - 1) * |kFileSize|
783 const int kTotalFileSize = 6000; 744 const int kTotalFileSize = 6000;
784 const int kNumEvents = 50; 745 const int kNumEvents = 50;
785 const int kEventSize = 200; 746 const int kEventSize = 200;
786 const int kFileSize = kTotalFileSize / kTotalNumFiles; 747 const int kFileSize = kTotalFileSize / kTotalNumFiles;
787 TestClosure closure; 748 TestClosure closure;
788 749
789 StartObserving(nullptr, nullptr, kTotalFileSize, kTotalNumFiles); 750 CreateAndStartObserving(nullptr, kTotalFileSize, kTotalNumFiles);
790 751
791 AddEntries(logger_.get(), kNumEvents, kEventSize); 752 AddEntries(logger_.get(), kNumEvents, kEventSize);
792 753
793 logger_->StopObserving(nullptr, closure.closure()); 754 logger_->StopObserving(nullptr, closure.closure());
794 755
795 closure.WaitForResult(); 756 closure.WaitForResult();
796 757
797 std::unique_ptr<base::Value> root; 758 std::unique_ptr<base::Value> root;
798 base::ListValue* events; 759 base::ListValue* events;
799 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); 760 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events));
(...skipping 27 matching lines...) Expand all
827 // Check that there are events written to all files. 788 // Check that there are events written to all files.
828 for (int i = 0; i < kTotalNumFiles; i++) { 789 for (int i = 0; i < kTotalNumFiles; i++) {
829 ASSERT_GE(GetFileSize(GetEventFilePath(i)), 790 ASSERT_GE(GetFileSize(GetEventFilePath(i)),
830 static_cast<int64_t>(kEventSize)); 791 static_cast<int64_t>(kEventSize));
831 } 792 }
832 } 793 }
833 794
834 } // namespace 795 } // namespace
835 796
836 } // namespace net 797 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698