diff options
author | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 18:28:33 +0000 |
---|---|---|
committer | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 18:28:33 +0000 |
commit | f2a4232c0180dd938b7b5d25cdece7e7927c29eb (patch) | |
tree | 98c89212151a2dcf4ed557ae9c494b3b3060d5c2 | |
parent | 702a6a7200da7a1c3c9bc03d19cd7a1f7740e157 (diff) | |
download | chromium_src-f2a4232c0180dd938b7b5d25cdece7e7927c29eb.zip chromium_src-f2a4232c0180dd938b7b5d25cdece7e7927c29eb.tar.gz chromium_src-f2a4232c0180dd938b7b5d25cdece7e7927c29eb.tar.bz2 |
Change observer expectations
This should prevent some test flakyness we saw on vista.
Review URL: http://codereview.chromium.org/977003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41857 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_unittest.cc | 66 |
2 files changed, 44 insertions, 24 deletions
diff --git a/chrome/browser/sync/engine/syncer_thread.h b/chrome/browser/sync/engine/syncer_thread.h index 71cbcbe..75ddb32 100644 --- a/chrome/browser/sync/engine/syncer_thread.h +++ b/chrome/browser/sync/engine/syncer_thread.h @@ -55,7 +55,7 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>, FRIEND_TEST(SyncerThreadWithSyncerTest, Nudge); FRIEND_TEST(SyncerThreadWithSyncerTest, Throttling); FRIEND_TEST(SyncerThreadWithSyncerTest, AuthInvalid); - FRIEND_TEST(SyncerThreadWithSyncerTest, PauseWhileWaiting); + FRIEND_TEST(SyncerThreadWithSyncerTest, Pause); friend class SyncerThreadWithSyncerTest; friend class SyncerThreadFactory; public: diff --git a/chrome/browser/sync/engine/syncer_thread_unittest.cc b/chrome/browser/sync/engine/syncer_thread_unittest.cc index be6be6a..89d2cfc 100644 --- a/chrome/browser/sync/engine/syncer_thread_unittest.cc +++ b/chrome/browser/sync/engine/syncer_thread_unittest.cc @@ -22,6 +22,7 @@ using base::TimeTicks; using base::TimeDelta; using base::WaitableEvent; using testing::_; +using testing::AnyNumber; using testing::Field; namespace browser_sync { @@ -719,10 +720,10 @@ class ListenerMock { MOCK_METHOD1(HandleEvent, void(const SyncerEvent&)); }; -TEST_F(SyncerThreadWithSyncerTest, PauseWhileWaiting) { - WaitableEvent event(false, false); - SyncShareIntercept interceptor; - connection()->SetMidCommitObserver(&interceptor); +TEST_F(SyncerThreadWithSyncerTest, Pause) { + WaitableEvent sync_cycle_ended_event(false, false); + WaitableEvent paused_event(false, false); + WaitableEvent resumed_event(false, false); // We don't want a poll to happen during this test (except the first one). const TimeDelta poll_interval = TimeDelta::FromMinutes(5); syncer_thread()->SetSyncerShortPollInterval(poll_interval); @@ -736,39 +737,58 @@ TEST_F(SyncerThreadWithSyncerTest, PauseWhileWaiting) { EXPECT_CALL(listener, HandleEvent( Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). - Times(2); - EXPECT_CALL(listener, HandleEvent( - Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))); + Times(AnyNumber()); - EXPECT_TRUE(syncer_thread()->Start()); + // Syncer thread is not running, should fail. + EXPECT_FALSE(syncer_thread()->RequestPause()); + EXPECT_FALSE(syncer_thread()->RequestResume()); + + // Wait for the initial sync to complete. + EXPECT_CALL(listener, HandleEvent( + Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). + WillOnce(SignalEvent(&sync_cycle_ended_event)); + ASSERT_TRUE(syncer_thread()->Start()); metadb()->Open(); + sync_cycle_ended_event.Wait(); - // Wait for thread to be waiting. - interceptor.WaitForSyncShare(1, poll_interval + poll_interval); - EXPECT_EQ(1U, interceptor.times_sync_occured().size()); + // Request a pause. + EXPECT_CALL(listener, HandleEvent( + Field(&SyncerEvent::what_happened, SyncerEvent::PAUSED))). + WillOnce(SignalEvent(&paused_event)); + ASSERT_TRUE(syncer_thread()->RequestPause()); + paused_event.Wait(); + + // Resuming the pause. + EXPECT_CALL(listener, HandleEvent( + Field(&SyncerEvent::what_happened, SyncerEvent::RESUMED))). + WillOnce(SignalEvent(&resumed_event)); + ASSERT_TRUE(syncer_thread()->RequestResume()); + resumed_event.Wait(); + + // Not paused, should fail. + EXPECT_FALSE(syncer_thread()->RequestResume()); // Request a pause. EXPECT_CALL(listener, HandleEvent( Field(&SyncerEvent::what_happened, SyncerEvent::PAUSED))). - WillOnce(SignalEvent(&event)); + WillOnce(SignalEvent(&paused_event)); ASSERT_TRUE(syncer_thread()->RequestPause()); - event.Wait(); + paused_event.Wait(); - // Nudge the syncer, this should do nothing while we are paused. If - // it does, the next test of "times sync occured" will fail. + // Nudge the syncer, this should do nothing while we are paused. syncer_thread()->NudgeSyncer(0, SyncerThread::kUnknown); - // Resuming will cause the thread to wait again without running the - // syncer. + // Resuming will cause the nudge to be processed and a sync cycle to run. EXPECT_CALL(listener, HandleEvent( Field(&SyncerEvent::what_happened, SyncerEvent::RESUMED))). - WillOnce(SignalEvent(&event)); + WillOnce(SignalEvent(&resumed_event)); + // Wait for the sync cycle to run. + EXPECT_CALL(listener, HandleEvent( + Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). + WillOnce(SignalEvent(&sync_cycle_ended_event)); ASSERT_TRUE(syncer_thread()->RequestResume()); - event.Wait(); - - // Confirm the syncer ran immediately after resume. - interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); - EXPECT_EQ(2U, interceptor.times_sync_occured().size()); + resumed_event.Wait(); + sync_cycle_ended_event.Wait(); EXPECT_TRUE(syncer_thread()->Stop(2000)); } |