OLD | NEW |
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 "net/dns/serial_worker.h" | 5 #include "net/dns/serial_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Lets OnWork run and waits for it to complete. Can only return if OnWork is | 90 // Lets OnWork run and waits for it to complete. Can only return if OnWork is |
91 // executed on a concurrent thread. | 91 // executed on a concurrent thread. |
92 void WaitForWork() { | 92 void WaitForWork() { |
93 RunUntilBreak("OnWork"); | 93 RunUntilBreak("OnWork"); |
94 work_allowed_.Signal(); | 94 work_allowed_.Signal(); |
95 work_called_.Wait(); | 95 work_called_.Wait(); |
96 } | 96 } |
97 | 97 |
98 // test::Test methods | 98 // test::Test methods |
99 virtual void SetUp() override { | 99 void SetUp() override { |
100 message_loop_ = base::MessageLoop::current(); | 100 message_loop_ = base::MessageLoop::current(); |
101 worker_ = new TestSerialWorker(this); | 101 worker_ = new TestSerialWorker(this); |
102 } | 102 } |
103 | 103 |
104 virtual void TearDown() override { | 104 void TearDown() override { |
105 // Cancel the worker to catch if it makes a late DoWork call. | 105 // Cancel the worker to catch if it makes a late DoWork call. |
106 worker_->Cancel(); | 106 worker_->Cancel(); |
107 // Check if OnWork is stalled. | 107 // Check if OnWork is stalled. |
108 EXPECT_FALSE(work_running_) << "OnWork should be done by TearDown"; | 108 EXPECT_FALSE(work_running_) << "OnWork should be done by TearDown"; |
109 // Release it for cleanliness. | 109 // Release it for cleanliness. |
110 if (work_running_) { | 110 if (work_running_) { |
111 WaitForWork(); | 111 WaitForWork(); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 RunUntilBreak("OnWorkFinished"); | 154 RunUntilBreak("OnWorkFinished"); |
155 | 155 |
156 // No more tasks should remain. | 156 // No more tasks should remain. |
157 EXPECT_TRUE(message_loop_->IsIdleForTesting()); | 157 EXPECT_TRUE(message_loop_->IsIdleForTesting()); |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 } // namespace net | 162 } // namespace net |
163 | 163 |
OLD | NEW |