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

Side by Side Diff: webrtc/modules/utility/source/process_thread_impl_unittest.cc

Issue 2708433002: Replace the stop_event_ in PlatformThread with an atomic flag (Closed)
Patch Set: Now hitting 'save' before committing the TODO Created 3 years, 10 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 | « webrtc/base/platform_thread.cc ('k') | 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 // Verifies that we get at least call back to Process() on the worker thread. 80 // Verifies that we get at least call back to Process() on the worker thread.
81 TEST(ProcessThreadImpl, ProcessCall) { 81 TEST(ProcessThreadImpl, ProcessCall) {
82 ProcessThreadImpl thread("ProcessThread"); 82 ProcessThreadImpl thread("ProcessThread");
83 thread.Start(); 83 thread.Start();
84 84
85 std::unique_ptr<EventWrapper> event(EventWrapper::Create()); 85 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
86 86
87 MockModule module; 87 MockModule module;
88 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 88 EXPECT_CALL(module, TimeUntilNextProcess())
89 .WillOnce(Return(0))
90 .WillRepeatedly(Return(1));
89 EXPECT_CALL(module, Process()) 91 EXPECT_CALL(module, Process())
90 .WillOnce(DoAll(SetEvent(event.get()), Return())) 92 .WillOnce(DoAll(SetEvent(event.get()), Return()))
91 .WillRepeatedly(Return()); 93 .WillRepeatedly(Return());
92 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 94 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
93 95
94 thread.RegisterModule(&module); 96 thread.RegisterModule(&module);
95 EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); 97 EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
96 98
97 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 99 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
98 thread.Stop(); 100 thread.Stop();
99 } 101 }
100 102
101 // Same as ProcessCall except the module is registered before the 103 // Same as ProcessCall except the module is registered before the
102 // call to Start(). 104 // call to Start().
103 TEST(ProcessThreadImpl, ProcessCall2) { 105 TEST(ProcessThreadImpl, ProcessCall2) {
104 ProcessThreadImpl thread("ProcessThread"); 106 ProcessThreadImpl thread("ProcessThread");
105 std::unique_ptr<EventWrapper> event(EventWrapper::Create()); 107 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
106 108
107 MockModule module; 109 MockModule module;
108 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 110 EXPECT_CALL(module, TimeUntilNextProcess())
111 .WillOnce(Return(0))
112 .WillRepeatedly(Return(1));
109 EXPECT_CALL(module, Process()) 113 EXPECT_CALL(module, Process())
110 .WillOnce(DoAll(SetEvent(event.get()), Return())) 114 .WillOnce(DoAll(SetEvent(event.get()), Return()))
111 .WillRepeatedly(Return()); 115 .WillRepeatedly(Return());
112 116
113 thread.RegisterModule(&module); 117 thread.RegisterModule(&module);
114 118
115 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 119 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
116 thread.Start(); 120 thread.Start();
117 EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); 121 EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
118 122
119 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 123 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
120 thread.Stop(); 124 thread.Stop();
121 } 125 }
122 126
123 // Tests setting up a module for callbacks and then unregister that module. 127 // Tests setting up a module for callbacks and then unregister that module.
124 // After unregistration, we should not receive any further callbacks. 128 // After unregistration, we should not receive any further callbacks.
125 TEST(ProcessThreadImpl, Deregister) { 129 TEST(ProcessThreadImpl, Deregister) {
126 ProcessThreadImpl thread("ProcessThread"); 130 ProcessThreadImpl thread("ProcessThread");
127 std::unique_ptr<EventWrapper> event(EventWrapper::Create()); 131 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
128 132
129 int process_count = 0; 133 int process_count = 0;
130 MockModule module; 134 MockModule module;
131 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 135 EXPECT_CALL(module, TimeUntilNextProcess())
136 .WillOnce(Return(0))
137 .WillRepeatedly(Return(1));
132 EXPECT_CALL(module, Process()) 138 EXPECT_CALL(module, Process())
133 .WillOnce(DoAll(SetEvent(event.get()), 139 .WillOnce(DoAll(SetEvent(event.get()),
134 Increment(&process_count), 140 Increment(&process_count),
135 Return())) 141 Return()))
136 .WillRepeatedly(DoAll(Increment(&process_count), Return())); 142 .WillRepeatedly(DoAll(Increment(&process_count), Return()));
137 143
138 thread.RegisterModule(&module); 144 thread.RegisterModule(&module);
139 145
140 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 146 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
141 thread.Start(); 147 thread.Start();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 ProcessThreadImpl thread("ProcessThread"); 311 ProcessThreadImpl thread("ProcessThread");
306 std::unique_ptr<EventWrapper> task_ran(EventWrapper::Create()); 312 std::unique_ptr<EventWrapper> task_ran(EventWrapper::Create());
307 std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); 313 std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
308 thread.Start(); 314 thread.Start();
309 thread.PostTask(std::move(task)); 315 thread.PostTask(std::move(task));
310 EXPECT_EQ(kEventSignaled, task_ran->Wait(kEventWaitTimeout)); 316 EXPECT_EQ(kEventSignaled, task_ran->Wait(kEventWaitTimeout));
311 thread.Stop(); 317 thread.Stop();
312 } 318 }
313 319
314 } // namespace webrtc 320 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/base/platform_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698