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

Side by Side Diff: chrome/browser/sync/profile_sync_service_harness.cc

Issue 7477004: Simulate transient error and verify exponential backoff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/profile_sync_service_harness.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <ostream> 10 #include <ostream>
11 #include <set> 11 #include <set>
12 #include <sstream> 12 #include <sstream>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "base/task.h" 19 #include "base/task.h"
20 #include "base/test/test_timeouts.h"
Raghu Simha 2011/08/05 22:45:09 Does this need to be included?
lipalani1 2011/08/05 23:09:29 Done.
20 #include "base/tracked.h" 21 #include "base/tracked.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sync/sessions/session_state.h" 23 #include "chrome/browser/sync/sessions/session_state.h"
23 #include "chrome/browser/sync/signin_manager.h" 24 #include "chrome/browser/sync/signin_manager.h"
24 #include "chrome/browser/sync/sync_ui_util.h" 25 #include "chrome/browser/sync/sync_ui_util.h"
25 26
26 using browser_sync::sessions::SyncSessionSnapshot; 27 using browser_sync::sessions::SyncSessionSnapshot;
27 28
29 // TODO (rsimha): Remove the following lines once crbug.com/91863 is fixed.
Raghu Simha 2011/08/05 22:45:09 No space between TODO and open paren. (The "TODOs"
lipalani1 2011/08/05 23:09:29 Done.
28 // The amount of time for which we wait for a live sync operation to complete. 30 // The amount of time for which we wait for a live sync operation to complete.
29 static const int kLiveSyncOperationTimeoutMs = 45000; 31 static const int kLiveSyncOperationTimeoutMs = 45000;
30 32
33 // The amount of time we wait for testcases that verify exponential backoff.
Raghu Simha 2011/08/05 22:45:09 nit: s/testcases/test cases/
lipalani1 2011/08/05 23:09:29 Done.
34 static const int kExponentialBackoffVerificationTimeoutMs = 60000;
35
31 // Simple class to implement a timeout using PostDelayedTask. If it is not 36 // Simple class to implement a timeout using PostDelayedTask. If it is not
32 // aborted before picked up by a message queue, then it asserts with the message 37 // aborted before picked up by a message queue, then it asserts with the message
33 // provided. This class is not thread safe. 38 // provided. This class is not thread safe.
34 class StateChangeTimeoutEvent 39 class StateChangeTimeoutEvent
35 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { 40 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> {
36 public: 41 public:
37 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, 42 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller,
38 const std::string& message); 43 const std::string& message);
39 44
40 // The entry point to the class from PostDelayedTask. 45 // The entry point to the class from PostDelayedTask.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 break; 325 break;
321 } 326 }
322 case WAITING_FOR_SYNC_DISABLED: { 327 case WAITING_FOR_SYNC_DISABLED: {
323 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); 328 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED");
324 if (service()->HasSyncSetupCompleted() == false) { 329 if (service()->HasSyncSetupCompleted() == false) {
325 // Sync has been disabled. 330 // Sync has been disabled.
326 SignalStateCompleteWithNextState(SYNC_DISABLED); 331 SignalStateCompleteWithNextState(SYNC_DISABLED);
327 } 332 }
328 break; 333 break;
329 } 334 }
335 case WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION: {
336 VLOG(1) << GetClientInfoString(
337 "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION");
338 retry_verifier_.VerifyRetryInterval(*GetLastSessionSnapshot());
Raghu Simha 2011/08/05 22:45:09 This will segfault if GetLastSessionSnapshot() ret
lipalani1 2011/08/05 23:09:29 Done.
339 if (retry_verifier_.Done())
340 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
341 break;
342 }
330 case SERVER_UNREACHABLE: { 343 case SERVER_UNREACHABLE: {
331 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); 344 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE");
332 if (GetStatus().server_reachable) { 345 if (GetStatus().server_reachable) {
333 // The client was offline due to the network being disabled, but is now 346 // The client was offline due to the network being disabled, but is now
334 // back online. Wait for the pending sync cycle to complete. 347 // back online. Wait for the pending sync cycle to complete.
335 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); 348 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH);
336 } 349 }
337 break; 350 break;
338 } 351 }
339 case SET_PASSPHRASE_FAILED: { 352 case SET_PASSPHRASE_FAILED: {
340 // A passphrase is required for decryption. There is nothing the sync 353 // A passphrase is required for decryption. There is nothing the sync
341 // client can do until SetPassphrase() is called. 354 // client can do until SetPassphrase() is called.
342 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); 355 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED");
343 break; 356 break;
344 } 357 }
345 case FULLY_SYNCED: { 358 case FULLY_SYNCED: {
346 // The client is online and fully synced. There is nothing to do. 359 // The client is online and fully synced. There is nothing to do.
347 VLOG(1) << GetClientInfoString("FULLY_SYNCED"); 360 VLOG(1) << GetClientInfoString("FULLY_SYNCED");
348 break; 361 break;
349 } 362 }
350 case SYNC_DISABLED: { 363 case SYNC_DISABLED: {
351 // Syncing is disabled for the client. There is nothing to do. 364 // Syncing is disabled for the client. There is nothing to do.
352 VLOG(1) << GetClientInfoString("SYNC_DISABLED"); 365 VLOG(1) << GetClientInfoString("SYNC_DISABLED");
353 break; 366 break;
354 } 367 }
Raghu Simha 2011/08/05 22:45:09 Handle the WAITING_FOR_NOTHING case here. All you
lipalani1 2011/08/05 23:09:29 Done.
355 default: 368 default:
356 // Invalid state during observer callback which may be triggered by other 369 // Invalid state during observer callback which may be triggered by other
357 // classes using the the UI message loop. Defer to their handling. 370 // classes using the the UI message loop. Defer to their handling.
358 break; 371 break;
359 } 372 }
360 return original_wait_state != wait_state_; 373 return original_wait_state != wait_state_;
361 } 374 }
362 375
363 void ProfileSyncServiceHarness::OnStateChanged() { 376 void ProfileSyncServiceHarness::OnStateChanged() {
364 RunStateChangeMachine(); 377 RunStateChangeMachine();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 483 }
471 484
472 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { 485 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) {
473 DCHECK(service()->HasSyncSetupCompleted()); 486 DCHECK(service()->HasSyncSetupCompleted());
474 DCHECK_NE(wait_state_, SYNC_DISABLED); 487 DCHECK_NE(wait_state_, SYNC_DISABLED);
475 wait_state_ = WAITING_FOR_SYNC_DISABLED; 488 wait_state_ = WAITING_FOR_SYNC_DISABLED;
476 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 489 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
477 return wait_state_ == SYNC_DISABLED; 490 return wait_state_ == SYNC_DISABLED;
478 } 491 }
479 492
493 bool ProfileSyncServiceHarness::AwaitExponentialBackoffVerification() {
494 retry_verifier_.Initialize(*GetLastSessionSnapshot());
Raghu Simha 2011/08/05 22:45:09 This will segfault if GetLastSessionSnapshot() ret
lipalani1 2011/08/05 23:09:29 Done.
Raghu Simha 2011/08/05 23:23:58 Still need a null check here.
495 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION;
496 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs,
497 "Verify Exponential backoff");
498 return (retry_verifier_.Success());
499 }
500
480 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 501 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
481 ProfileSyncServiceHarness* partner) { 502 ProfileSyncServiceHarness* partner) {
482 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); 503 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion");
483 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) 504 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client."))
484 return false; 505 return false;
485 return partner->WaitUntilTimestampMatches(this, 506 return partner->WaitUntilTimestampMatches(this,
486 "Sync cycle completion on passive client."); 507 "Sync cycle completion on passive client.");
487 } 508 }
488 509
489 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 510 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 return true; 853 return true;
833 } 854 }
834 855
835 std::string ProfileSyncServiceHarness::GetServiceStatus() { 856 std::string ProfileSyncServiceHarness::GetServiceStatus() {
836 DictionaryValue value; 857 DictionaryValue value;
837 sync_ui_util::ConstructAboutInformation(service_, &value); 858 sync_ui_util::ConstructAboutInformation(service_, &value);
838 std::string service_status; 859 std::string service_status;
839 base::JSONWriter::Write(&value, true, &service_status); 860 base::JSONWriter::Write(&value, true, &service_status);
840 return service_status; 861 return service_status;
841 } 862 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698