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

Side by Side Diff: webrtc/base/signalthread_unittest.cc

Issue 2029853002: Fixing flaky SignalThread tests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master, un-disable flaky tests. Created 4 years, 6 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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/base/constructormagic.h" 13 #include "webrtc/base/constructormagic.h"
14 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/signalthread.h" 15 #include "webrtc/base/signalthread.h"
16 #include "webrtc/base/thread.h" 16 #include "webrtc/base/thread.h"
17 17
18 using namespace rtc; 18 using namespace rtc;
19 19
20 // 10 seconds.
21 static const int kTimeout = 10000;
22
20 class SignalThreadTest : public testing::Test, public sigslot::has_slots<> { 23 class SignalThreadTest : public testing::Test, public sigslot::has_slots<> {
21 public: 24 public:
22 class SlowSignalThread : public SignalThread { 25 class SlowSignalThread : public SignalThread {
23 public: 26 public:
24 SlowSignalThread(SignalThreadTest* harness) : harness_(harness) { 27 SlowSignalThread(SignalThreadTest* harness) : harness_(harness) {
25 } 28 }
26 29
27 virtual ~SlowSignalThread() { 30 virtual ~SlowSignalThread() {
28 EXPECT_EQ(harness_->main_thread_, Thread::Current()); 31 EXPECT_EQ(harness_->main_thread_, Thread::Current());
29 ++harness_->thread_deleted_; 32 ++harness_->thread_deleted_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 Thread::Current()->socketserver()->Wait(500, false); 155 Thread::Current()->socketserver()->Wait(500, false);
153 } 156 }
154 157
155 #define EXPECT_STATE(started, done, completed, stopped, deleted) \ 158 #define EXPECT_STATE(started, done, completed, stopped, deleted) \
156 EXPECT_EQ(started, thread_started_); \ 159 EXPECT_EQ(started, thread_started_); \
157 EXPECT_EQ(done, thread_done_); \ 160 EXPECT_EQ(done, thread_done_); \
158 EXPECT_EQ(completed, thread_completed_); \ 161 EXPECT_EQ(completed, thread_completed_); \
159 EXPECT_EQ(stopped, thread_stopped_); \ 162 EXPECT_EQ(stopped, thread_stopped_); \
160 EXPECT_EQ(deleted, thread_deleted_); 163 EXPECT_EQ(deleted, thread_deleted_);
161 164
162 #if defined(WEBRTC_LINUX) 165 #define EXPECT_STATE_WAIT(started, done, completed, stopped, deleted, timeout) \
163 #define MAYBE_ThreadFinishes DISABLED_ThreadFinishes 166 EXPECT_EQ_WAIT(started, thread_started_, timeout); \
164 #else 167 EXPECT_EQ_WAIT(done, thread_done_, timeout); \
165 #define MAYBE_ThreadFinishes ThreadFinishes 168 EXPECT_EQ_WAIT(completed, thread_completed_, timeout); \
166 #endif 169 EXPECT_EQ_WAIT(stopped, thread_stopped_, timeout); \
167 TEST_F(SignalThreadTest, MAYBE_ThreadFinishes) { 170 EXPECT_EQ_WAIT(deleted, thread_deleted_, timeout);
171
172 TEST_F(SignalThreadTest, ThreadFinishes) {
168 thread_->Start(); 173 thread_->Start();
169 EXPECT_STATE(1, 0, 0, 0, 0); 174 EXPECT_STATE(1, 0, 0, 0, 0);
170 Thread::SleepMs(500); 175 EXPECT_STATE_WAIT(1, 1, 1, 0, 1, kTimeout);
171 EXPECT_STATE(1, 0, 0, 0, 0);
172 Thread::Current()->ProcessMessages(0);
173 EXPECT_STATE(1, 1, 1, 0, 1);
174 } 176 }
175 177
176 #if defined(WEBRTC_LINUX) 178 TEST_F(SignalThreadTest, ReleasedThreadFinishes) {
177 #define MAYBE_ReleasedThreadFinishes DISABLED_ReleasedThreadFinishes
178 #else
179 #define MAYBE_ReleasedThreadFinishes ReleasedThreadFinishes
180 #endif
181 TEST_F(SignalThreadTest, MAYBE_ReleasedThreadFinishes) {
182 thread_->Start(); 179 thread_->Start();
183 EXPECT_STATE(1, 0, 0, 0, 0); 180 EXPECT_STATE(1, 0, 0, 0, 0);
184 thread_->Release(); 181 thread_->Release();
185 called_release_ = true; 182 called_release_ = true;
186 EXPECT_STATE(1, 0, 0, 0, 0); 183 EXPECT_STATE(1, 0, 0, 0, 0);
187 Thread::SleepMs(500); 184 EXPECT_STATE_WAIT(1, 1, 1, 0, 1, kTimeout);
188 EXPECT_STATE(1, 0, 0, 0, 0);
189 Thread::Current()->ProcessMessages(0);
190 EXPECT_STATE(1, 1, 1, 0, 1);
191 } 185 }
192 186
193 TEST_F(SignalThreadTest, DestroyedThreadCleansUp) { 187 TEST_F(SignalThreadTest, DestroyedThreadCleansUp) {
194 thread_->Start(); 188 thread_->Start();
195 EXPECT_STATE(1, 0, 0, 0, 0); 189 EXPECT_STATE(1, 0, 0, 0, 0);
196 thread_->Destroy(true); 190 thread_->Destroy(true);
197 EXPECT_STATE(1, 0, 0, 1, 1); 191 EXPECT_STATE(1, 0, 0, 1, 1);
198 Thread::Current()->ProcessMessages(0); 192 Thread::Current()->ProcessMessages(0);
199 EXPECT_STATE(1, 0, 0, 1, 1); 193 EXPECT_STATE(1, 0, 0, 1, 1);
200 } 194 }
201 195
202 TEST_F(SignalThreadTest, DeferredDestroyedThreadCleansUp) { 196 TEST_F(SignalThreadTest, DeferredDestroyedThreadCleansUp) {
203 thread_->Start(); 197 thread_->Start();
204 EXPECT_STATE(1, 0, 0, 0, 0); 198 EXPECT_STATE(1, 0, 0, 0, 0);
205 thread_->Destroy(false); 199 thread_->Destroy(false);
206 EXPECT_STATE(1, 0, 0, 1, 0); 200 EXPECT_STATE(1, 0, 0, 1, 0);
207 Thread::SleepMs(500); 201 EXPECT_STATE_WAIT(1, 1, 0, 1, 1, kTimeout);
208 EXPECT_STATE(1, 0, 0, 1, 0);
209 Thread::Current()->ProcessMessages(0);
210 EXPECT_STATE(1, 1, 0, 1, 1);
211 } 202 }
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