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

Side by Side Diff: base/threading/worker_pool_unittest.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 years, 8 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 | « base/threading/thread_unittest.cc ('k') | base/timer/timer.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/threading/worker_pool.h" 5 #include "base/threading/worker_pool.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 16 matching lines...) Expand all
27 : public base::RefCountedThreadSafe<PostTaskAndReplyTester> { 27 : public base::RefCountedThreadSafe<PostTaskAndReplyTester> {
28 public: 28 public:
29 PostTaskAndReplyTester() 29 PostTaskAndReplyTester()
30 : finished_(false), 30 : finished_(false),
31 test_event_(WaitableEvent::ResetPolicy::AUTOMATIC, 31 test_event_(WaitableEvent::ResetPolicy::AUTOMATIC,
32 WaitableEvent::InitialState::NOT_SIGNALED) {} 32 WaitableEvent::InitialState::NOT_SIGNALED) {}
33 33
34 void RunTest() { 34 void RunTest() {
35 ASSERT_TRUE(thread_checker_.CalledOnValidThread()); 35 ASSERT_TRUE(thread_checker_.CalledOnValidThread());
36 WorkerPool::PostTaskAndReply( 36 WorkerPool::PostTaskAndReply(
37 FROM_HERE, 37 FROM_HERE,
38 base::Bind(&PostTaskAndReplyTester::OnWorkerThread, this), 38 base::BindOnce(&PostTaskAndReplyTester::OnWorkerThread, this),
39 base::Bind(&PostTaskAndReplyTester::OnOriginalThread, this), 39 base::BindOnce(&PostTaskAndReplyTester::OnOriginalThread, this), false);
40 false);
41 40
42 test_event_.Wait(); 41 test_event_.Wait();
43 } 42 }
44 43
45 void OnWorkerThread() { 44 void OnWorkerThread() {
46 // We're not on the original thread. 45 // We're not on the original thread.
47 EXPECT_FALSE(thread_checker_.CalledOnValidThread()); 46 EXPECT_FALSE(thread_checker_.CalledOnValidThread());
48 47
49 test_event_.Signal(); 48 test_event_.Signal();
50 } 49 }
(...skipping 19 matching lines...) Expand all
70 }; 69 };
71 70
72 } // namespace 71 } // namespace
73 72
74 TEST_F(WorkerPoolTest, PostTask) { 73 TEST_F(WorkerPoolTest, PostTask) {
75 WaitableEvent test_event(WaitableEvent::ResetPolicy::AUTOMATIC, 74 WaitableEvent test_event(WaitableEvent::ResetPolicy::AUTOMATIC,
76 WaitableEvent::InitialState::NOT_SIGNALED); 75 WaitableEvent::InitialState::NOT_SIGNALED);
77 WaitableEvent long_test_event(WaitableEvent::ResetPolicy::AUTOMATIC, 76 WaitableEvent long_test_event(WaitableEvent::ResetPolicy::AUTOMATIC,
78 WaitableEvent::InitialState::NOT_SIGNALED); 77 WaitableEvent::InitialState::NOT_SIGNALED);
79 78
79 WorkerPool::PostTask(
80 FROM_HERE,
81 base::BindOnce(&WaitableEvent::Signal, base::Unretained(&test_event)),
82 false);
80 WorkerPool::PostTask(FROM_HERE, 83 WorkerPool::PostTask(FROM_HERE,
81 base::Bind(&WaitableEvent::Signal, 84 base::BindOnce(&WaitableEvent::Signal,
82 base::Unretained(&test_event)), 85 base::Unretained(&long_test_event)),
83 false);
84 WorkerPool::PostTask(FROM_HERE,
85 base::Bind(&WaitableEvent::Signal,
86 base::Unretained(&long_test_event)),
87 true); 86 true);
88 87
89 test_event.Wait(); 88 test_event.Wait();
90 long_test_event.Wait(); 89 long_test_event.Wait();
91 } 90 }
92 91
93 #if defined(OS_WIN) || defined(OS_LINUX) 92 #if defined(OS_WIN) || defined(OS_LINUX)
94 // Flaky on Windows and Linux (http://crbug.com/130337) 93 // Flaky on Windows and Linux (http://crbug.com/130337)
95 #define MAYBE_PostTaskAndReply DISABLED_PostTaskAndReply 94 #define MAYBE_PostTaskAndReply DISABLED_PostTaskAndReply
96 #else 95 #else
(...skipping 12 matching lines...) Expand all
109 // Ensure that the other thread has a chance to run even on a single-core 108 // Ensure that the other thread has a chance to run even on a single-core
110 // device. 109 // device.
111 pthread_yield_np(); 110 pthread_yield_np();
112 #endif 111 #endif
113 RunLoop().RunUntilIdle(); 112 RunLoop().RunUntilIdle();
114 } 113 }
115 EXPECT_TRUE(tester->finished()); 114 EXPECT_TRUE(tester->finished());
116 } 115 }
117 116
118 } // namespace base 117 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/thread_unittest.cc ('k') | base/timer/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698