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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 61213009: Don't drop debug_info when posting to sync server fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed erroneous use of SYNC_EXPORT_PRIVATE from MockDebugInfoGetter. Created 7 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 unified diff | Download patch
« no previous file with comments | « sync/engine/download_unittest.cc ('k') | sync/internal_api/debug_info_event_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "sync/syncable/syncable_read_transaction.h" 43 #include "sync/syncable/syncable_read_transaction.h"
44 #include "sync/syncable/syncable_util.h" 44 #include "sync/syncable/syncable_util.h"
45 #include "sync/syncable/syncable_write_transaction.h" 45 #include "sync/syncable/syncable_write_transaction.h"
46 #include "sync/test/engine/fake_model_worker.h" 46 #include "sync/test/engine/fake_model_worker.h"
47 #include "sync/test/engine/mock_connection_manager.h" 47 #include "sync/test/engine/mock_connection_manager.h"
48 #include "sync/test/engine/test_directory_setter_upper.h" 48 #include "sync/test/engine/test_directory_setter_upper.h"
49 #include "sync/test/engine/test_id_factory.h" 49 #include "sync/test/engine/test_id_factory.h"
50 #include "sync/test/engine/test_syncable_utils.h" 50 #include "sync/test/engine/test_syncable_utils.h"
51 #include "sync/test/fake_encryptor.h" 51 #include "sync/test/fake_encryptor.h"
52 #include "sync/test/fake_sync_encryption_handler.h" 52 #include "sync/test/fake_sync_encryption_handler.h"
53 #include "sync/test/sessions/mock_debug_info_getter.h"
53 #include "sync/util/cryptographer.h" 54 #include "sync/util/cryptographer.h"
54 #include "sync/util/extensions_activity.h" 55 #include "sync/util/extensions_activity.h"
55 #include "sync/util/time.h" 56 #include "sync/util/time.h"
56 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
57 58
58 using base::TimeDelta; 59 using base::TimeDelta;
59 60
60 using std::count; 61 using std::count;
61 using std::map; 62 using std::map;
62 using std::multimap; 63 using std::multimap;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 using syncable::SERVER_IS_DEL; 98 using syncable::SERVER_IS_DEL;
98 using syncable::SERVER_PARENT_ID; 99 using syncable::SERVER_PARENT_ID;
99 using syncable::SERVER_SPECIFICS; 100 using syncable::SERVER_SPECIFICS;
100 using syncable::SERVER_VERSION; 101 using syncable::SERVER_VERSION;
101 using syncable::UNIQUE_CLIENT_TAG; 102 using syncable::UNIQUE_CLIENT_TAG;
102 using syncable::UNIQUE_SERVER_TAG; 103 using syncable::UNIQUE_SERVER_TAG;
103 using syncable::SPECIFICS; 104 using syncable::SPECIFICS;
104 using syncable::SYNCING; 105 using syncable::SYNCING;
105 using syncable::UNITTEST; 106 using syncable::UNITTEST;
106 107
108 using sessions::MockDebugInfoGetter;
107 using sessions::StatusController; 109 using sessions::StatusController;
108 using sessions::SyncSessionContext; 110 using sessions::SyncSessionContext;
109 using sessions::SyncSession; 111 using sessions::SyncSession;
110 112
111 class SyncerTest : public testing::Test, 113 class SyncerTest : public testing::Test,
112 public SyncSession::Delegate, 114 public SyncSession::Delegate,
113 public SyncEngineEventListener { 115 public SyncEngineEventListener {
114 protected: 116 protected:
115 SyncerTest() 117 SyncerTest()
116 : extensions_activity_(new ExtensionsActivity), 118 : extensions_activity_(new ExtensionsActivity),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 EXPECT_TRUE(syncer_->ConfigureSyncShare( 199 EXPECT_TRUE(syncer_->ConfigureSyncShare(
198 GetRoutingInfoTypes(context_->routing_info()), 200 GetRoutingInfoTypes(context_->routing_info()),
199 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 201 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
200 session_.get())); 202 session_.get()));
201 } 203 }
202 204
203 virtual void SetUp() { 205 virtual void SetUp() {
204 dir_maker_.SetUp(); 206 dir_maker_.SetUp();
205 mock_server_.reset(new MockConnectionManager(directory(), 207 mock_server_.reset(new MockConnectionManager(directory(),
206 &cancelation_signal_)); 208 &cancelation_signal_));
209 debug_info_getter_.reset(new MockDebugInfoGetter);
207 EnableDatatype(BOOKMARKS); 210 EnableDatatype(BOOKMARKS);
208 EnableDatatype(NIGORI); 211 EnableDatatype(NIGORI);
209 EnableDatatype(PREFERENCES); 212 EnableDatatype(PREFERENCES);
210 EnableDatatype(NIGORI); 213 EnableDatatype(NIGORI);
211 worker_ = new FakeModelWorker(GROUP_PASSIVE); 214 worker_ = new FakeModelWorker(GROUP_PASSIVE);
212 std::vector<SyncEngineEventListener*> listeners; 215 std::vector<SyncEngineEventListener*> listeners;
213 listeners.push_back(this); 216 listeners.push_back(this);
214 217
215 ModelSafeRoutingInfo routing_info; 218 ModelSafeRoutingInfo routing_info;
216 std::vector<ModelSafeWorker*> workers; 219 std::vector<ModelSafeWorker*> workers;
217 220
218 GetModelSafeRoutingInfo(&routing_info); 221 GetModelSafeRoutingInfo(&routing_info);
219 GetWorkers(&workers); 222 GetWorkers(&workers);
220 223
221 context_.reset( 224 context_.reset(
222 new SyncSessionContext( 225 new SyncSessionContext(
223 mock_server_.get(), directory(), workers, 226 mock_server_.get(), directory(), workers,
224 extensions_activity_, 227 extensions_activity_,
225 listeners, NULL, &traffic_recorder_, 228 listeners, debug_info_getter_.get(), &traffic_recorder_,
226 true, // enable keystore encryption 229 true, // enable keystore encryption
227 false, // force enable pre-commit GU avoidance experiment 230 false, // force enable pre-commit GU avoidance experiment
228 "fake_invalidator_client_id")); 231 "fake_invalidator_client_id"));
229 context_->set_routing_info(routing_info); 232 context_->set_routing_info(routing_info);
230 syncer_ = new Syncer(&cancelation_signal_); 233 syncer_ = new Syncer(&cancelation_signal_);
231 234
232 syncable::ReadTransaction trans(FROM_HERE, directory()); 235 syncable::ReadTransaction trans(FROM_HERE, directory());
233 syncable::Directory::Metahandles children; 236 syncable::Directory::Metahandles children;
234 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 237 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
235 ASSERT_EQ(0u, children.size()); 238 ASSERT_EQ(0u, children.size());
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 bool saw_syncer_event_; 486 bool saw_syncer_event_;
484 base::TimeDelta last_short_poll_interval_received_; 487 base::TimeDelta last_short_poll_interval_received_;
485 base::TimeDelta last_long_poll_interval_received_; 488 base::TimeDelta last_long_poll_interval_received_;
486 base::TimeDelta last_sessions_commit_delay_seconds_; 489 base::TimeDelta last_sessions_commit_delay_seconds_;
487 int last_client_invalidation_hint_buffer_size_; 490 int last_client_invalidation_hint_buffer_size_;
488 scoped_refptr<ModelSafeWorker> worker_; 491 scoped_refptr<ModelSafeWorker> worker_;
489 492
490 ModelTypeSet enabled_datatypes_; 493 ModelTypeSet enabled_datatypes_;
491 TrafficRecorder traffic_recorder_; 494 TrafficRecorder traffic_recorder_;
492 sessions::NudgeTracker nudge_tracker_; 495 sessions::NudgeTracker nudge_tracker_;
496 scoped_ptr<MockDebugInfoGetter> debug_info_getter_;
493 497
494 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 498 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
495 }; 499 };
496 500
497 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 501 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
498 { 502 {
499 Syncer::UnsyncedMetaHandles handles; 503 Syncer::UnsyncedMetaHandles handles;
500 { 504 {
501 syncable::ReadTransaction trans(FROM_HERE, directory()); 505 syncable::ReadTransaction trans(FROM_HERE, directory());
502 GetUnsyncedEntries(&trans, &handles); 506 GetUnsyncedEntries(&trans, &handles);
(...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 // Return a CONFLICT response for the first item. 2512 // Return a CONFLICT response for the first item.
2509 mock_server_->set_conflict_n_commits(1); 2513 mock_server_->set_conflict_n_commits(1);
2510 SyncShareNudge(); 2514 SyncShareNudge();
2511 2515
2512 // We should stop looping at the first sign of trouble. 2516 // We should stop looping at the first sign of trouble.
2513 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2517 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2514 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), 2518 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1),
2515 directory()->unsynced_entity_count()); 2519 directory()->unsynced_entity_count());
2516 } 2520 }
2517 2521
2522 // Tests that sending debug info events works.
2523 TEST_F(SyncerTest, SendDebugInfoEvents_HappyCase) {
2524 debug_info_getter_->AddDebugEvent();
2525 debug_info_getter_->AddDebugEvent();
2526
2527 SyncShareNudge();
2528
2529 // Verify we received one request with two debug info events.
2530 EXPECT_EQ(1U, mock_server_->requests().size());
2531 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size());
2532
2533 SyncShareNudge();
2534
2535 // See that we received another request, but that it contains no debug info
2536 // events.
2537 EXPECT_EQ(2U, mock_server_->requests().size());
2538 EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size());
2539
2540 debug_info_getter_->AddDebugEvent();
2541
2542 SyncShareNudge();
2543
2544 // See that we received another request and it contains one debug info event.
2545 EXPECT_EQ(3U, mock_server_->requests().size());
2546 EXPECT_EQ(1, mock_server_->requests().back().debug_info().events_size());
2547 }
2548
2549 // Tests that debug info events are dropped on server error.
2550 TEST_F(SyncerTest, SendDebugInfoEvents_PostFailsDontDrop) {
2551 debug_info_getter_->AddDebugEvent();
2552 debug_info_getter_->AddDebugEvent();
2553
2554 mock_server_->FailNextPostBufferToPathCall();
2555 SyncShareNudge();
2556
2557 // Verify we attempted to send one request with two debug info events.
2558 EXPECT_EQ(1U, mock_server_->requests().size());
2559 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size());
2560
2561 SyncShareNudge();
2562
2563 // See that the client resent the two debug info events.
2564 EXPECT_EQ(2U, mock_server_->requests().size());
2565 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size());
2566
2567 // The previous send was successful so this next one shouldn't generate any
2568 // debug info events.
2569 SyncShareNudge();
2570 EXPECT_EQ(3U, mock_server_->requests().size());
2571 EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size());
2572 }
2573
2518 TEST_F(SyncerTest, HugeConflict) { 2574 TEST_F(SyncerTest, HugeConflict) {
2519 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 2575 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
2520 2576
2521 syncable::Id parent_id = ids_.NewServerId(); 2577 syncable::Id parent_id = ids_.NewServerId();
2522 syncable::Id last_id = parent_id; 2578 syncable::Id last_id = parent_id;
2523 vector<syncable::Id> tree_ids; 2579 vector<syncable::Id> tree_ids;
2524 2580
2525 // Create a lot of updates for which the parent does not exist yet. 2581 // Create a lot of updates for which the parent does not exist yet.
2526 // Generate a huge deep tree which should all fail to apply at first. 2582 // Generate a huge deep tree which should all fail to apply at first.
2527 { 2583 {
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 4714 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
4659 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 4715 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
4660 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 4716 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
4661 } else { 4717 } else {
4662 EXPECT_TRUE(final_monitor_records.empty()) 4718 EXPECT_TRUE(final_monitor_records.empty())
4663 << "Should not restore records after successful bookmark commit."; 4719 << "Should not restore records after successful bookmark commit.";
4664 } 4720 }
4665 } 4721 }
4666 4722
4667 } // namespace syncer 4723 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/download_unittest.cc ('k') | sync/internal_api/debug_info_event_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698