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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread_unittest.cc

Issue 2991003: Fix race condition in test Pause method. (Closed)
Patch Set: Reenable test. Created 10 years, 5 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
« no previous file with comments | « no previous file | 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 8
9 #include "base/lock.h"
9 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 #include "base/waitable_event.h" 12 #include "base/waitable_event.h"
12 #include "chrome/browser/sync/engine/model_safe_worker.h" 13 #include "chrome/browser/sync/engine/model_safe_worker.h"
13 #include "chrome/browser/sync/engine/syncer_thread.h" 14 #include "chrome/browser/sync/engine/syncer_thread.h"
14 #include "chrome/browser/sync/engine/syncer_types.h" 15 #include "chrome/browser/sync/engine/syncer_types.h"
15 #include "chrome/browser/sync/sessions/sync_session_context.h" 16 #include "chrome/browser/sync/sessions/sync_session_context.h"
16 #include "chrome/browser/sync/util/channel.h" 17 #include "chrome/browser/sync/util/channel.h"
17 #include "chrome/test/sync/engine/mock_connection_manager.h" 18 #include "chrome/test/sync/engine/mock_connection_manager.h"
18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 19 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 while (syncer_thread()->vault_.connected_) { 110 while (syncer_thread()->vault_.connected_) {
110 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds); 111 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds);
111 if (TimeTicks::Now() - start > ten_seconds) 112 if (TimeTicks::Now() - start > ten_seconds)
112 break; 113 break;
113 } 114 }
114 EXPECT_FALSE(syncer_thread()->vault_.connected_); 115 EXPECT_FALSE(syncer_thread()->vault_.connected_);
115 } 116 }
116 117
117 bool Pause(ListenerMock* listener) { 118 bool Pause(ListenerMock* listener) {
118 WaitableEvent event(false, false); 119 WaitableEvent event(false, false);
119 EXPECT_CALL(*listener, HandleChannelEvent( 120 {
120 Field(&SyncerEvent::what_happened, SyncerEvent::PAUSED))). 121 AutoLock lock(syncer_thread()->lock_);
121 WillOnce(SignalEvent(&event)); 122 EXPECT_CALL(*listener, HandleChannelEvent(
123 Field(&SyncerEvent::what_happened, SyncerEvent::PAUSED))).
124 WillOnce(SignalEvent(&event));
125 }
122 if (!syncer_thread()->RequestPause()) 126 if (!syncer_thread()->RequestPause())
123 return false; 127 return false;
124 return event.TimedWait(max_wait_time_); 128 return event.TimedWait(max_wait_time_);
125 } 129 }
126 130
127 bool Resume(ListenerMock* listener) { 131 bool Resume(ListenerMock* listener) {
128 WaitableEvent event(false, false); 132 WaitableEvent event(false, false);
129 EXPECT_CALL(*listener, HandleChannelEvent( 133 {
130 Field(&SyncerEvent::what_happened, SyncerEvent::RESUMED))). 134 AutoLock lock(syncer_thread()->lock_);
131 WillOnce(SignalEvent(&event)); 135 EXPECT_CALL(*listener, HandleChannelEvent(
136 Field(&SyncerEvent::what_happened, SyncerEvent::RESUMED))).
137 WillOnce(SignalEvent(&event));
138 }
132 if (!syncer_thread()->RequestResume()) 139 if (!syncer_thread()->RequestResume())
133 return false; 140 return false;
134 return event.TimedWait(max_wait_time_); 141 return event.TimedWait(max_wait_time_);
135 } 142 }
136 143
137 void PreventThreadFromPolling() { 144 void PreventThreadFromPolling() {
138 const TimeDelta poll_interval = TimeDelta::FromMinutes(5); 145 const TimeDelta poll_interval = TimeDelta::FromMinutes(5);
139 syncer_thread()->SetSyncerShortPollInterval(poll_interval); 146 syncer_thread()->SetSyncerShortPollInterval(poll_interval);
140 } 147 }
141 148
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 EXPECT_FALSE(interceptor.times_sync_occured().empty()); 800 EXPECT_FALSE(interceptor.times_sync_occured().empty());
794 801
795 EXPECT_TRUE(syncer_thread()->Stop(2000)); 802 EXPECT_TRUE(syncer_thread()->Stop(2000));
796 } 803 }
797 804
798 // TODO(skrul): The "Pause" and "PauseWhenNotConnected" tests are 805 // TODO(skrul): The "Pause" and "PauseWhenNotConnected" tests are
799 // marked FLAKY because they sometimes fail on the Windows buildbots. 806 // marked FLAKY because they sometimes fail on the Windows buildbots.
800 // I have been unable to reproduce this hang after extensive testing 807 // I have been unable to reproduce this hang after extensive testing
801 // on a local Windows machine so these tests will remain flaky in 808 // on a local Windows machine so these tests will remain flaky in
802 // order to help diagnose the problem. 809 // order to help diagnose the problem.
803 // oshima: this is actually crashing and cause failure on XP Tests. 810 TEST_F(SyncerThreadWithSyncerTest, FLAKY_Pause) {
804 // Disabling on windows.
805 // This issue is tracked at http://crbug.com/39070.
806 #if defined(OS_WIN)
807 #define MAYBE_Pause DISABLED_Pause
808 #else
809 #define MAYBE_Pause Pause
810 #endif
811 TEST_F(SyncerThreadWithSyncerTest, MAYBE_Pause) {
812 WaitableEvent sync_cycle_ended_event(false, false); 811 WaitableEvent sync_cycle_ended_event(false, false);
813 WaitableEvent paused_event(false, false); 812 WaitableEvent paused_event(false, false);
814 WaitableEvent resumed_event(false, false); 813 WaitableEvent resumed_event(false, false);
815 PreventThreadFromPolling(); 814 PreventThreadFromPolling();
816 815
817 ListenerMock listener; 816 ListenerMock listener;
818 scoped_ptr<ChannelHookup<SyncerEvent> > hookup; 817 scoped_ptr<ChannelHookup<SyncerEvent> > hookup;
819 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); 818 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener));
820 819
821 EXPECT_CALL(listener, HandleChannelEvent( 820 EXPECT_CALL(listener, HandleChannelEvent(
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 WillOnce(SignalEvent(&sync_cycle_ended_event)); 1004 WillOnce(SignalEvent(&sync_cycle_ended_event));
1006 EXPECT_CALL(listener, HandleChannelEvent( 1005 EXPECT_CALL(listener, HandleChannelEvent(
1007 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); 1006 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING)));
1008 1007
1009 ASSERT_TRUE(Resume(&listener)); 1008 ASSERT_TRUE(Resume(&listener));
1010 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 1009 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
1011 EXPECT_TRUE(syncer_thread()->Stop(2000)); 1010 EXPECT_TRUE(syncer_thread()->Stop(2000));
1012 } 1011 }
1013 1012
1014 } // namespace browser_sync 1013 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698