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

Unified Diff: base/task_scheduler/task_tracker_unittest.cc

Issue 2798373002: Fix race condition in TaskSchedulerTaskTrackerTest.WillPostAndRunLongTaskBeforeShutdown. (Closed)
Patch Set: self-review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_tracker_unittest.cc
diff --git a/base/task_scheduler/task_tracker_unittest.cc b/base/task_scheduler/task_tracker_unittest.cc
index 85378b6234afe6a9f0ff499e00c6e66ec4b402c9..cbca5f3b8687b5f00498a06a71bc489beaac3834 100644
--- a/base/task_scheduler/task_tracker_unittest.cc
+++ b/base/task_scheduler/task_tracker_unittest.cc
@@ -263,24 +263,34 @@ TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunBeforeShutdown) {
}
TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) {
- // Create a task that will block until |event| is signaled.
- WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
- WaitableEvent::InitialState::NOT_SIGNALED);
+ // Create a task that signals |task_scheduled| and blocks until |task_barrier|
+ // is signaled.
+ WaitableEvent task_scheduled(WaitableEvent::ResetPolicy::AUTOMATIC,
robliao 2017/04/06 18:26:26 This might be clearer as task_running.
fdoray 2017/04/07 12:26:27 Done.
+ WaitableEvent::InitialState::NOT_SIGNALED);
+ WaitableEvent task_barrier(WaitableEvent::ResetPolicy::AUTOMATIC,
+ WaitableEvent::InitialState::NOT_SIGNALED);
auto blocked_task = base::MakeUnique<Task>(
- FROM_HERE, Bind(&WaitableEvent::Wait, Unretained(&event)),
+ FROM_HERE,
+ Bind(
+ [](WaitableEvent* task_scheduled, WaitableEvent* task_barrier) {
+ task_scheduled->Signal();
+ task_barrier->Wait();
+ },
+ Unretained(&task_scheduled), base::Unretained(&task_barrier)),
TaskTraits().WithBaseSyncPrimitives().WithShutdownBehavior(GetParam()),
TimeDelta());
// Inform |task_tracker_| that |blocked_task| will be posted.
EXPECT_TRUE(tracker_.WillPostTask(blocked_task.get()));
- // Run the task asynchronouly.
+ // Create a thread to run the task. Wait until the task starts running.
ThreadPostingAndRunningTask thread_running_task(
&tracker_, std::move(blocked_task),
ThreadPostingAndRunningTask::Action::RUN, false);
thread_running_task.Start();
+ task_scheduled.Wait();
- // Initiate shutdown while the task is running.
+ // Initiate shutdown after the task has been scheduled.
CallShutdownAsync();
if (GetParam() == TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) {
@@ -292,7 +302,7 @@ TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) {
}
// Unblock the task.
- event.Signal();
+ task_barrier.Signal();
thread_running_task.Join();
// Shutdown should now complete for a non CONTINUE_ON_SHUTDOWN task.
« 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