diff options
author | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-06 16:01:30 +0000 |
---|---|---|
committer | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-06 16:01:30 +0000 |
commit | b3cc0c25614566f1261b9c3759d6a076e327fd6c (patch) | |
tree | d19d4e3159b75c29f2410563a827be490929c3cd /base/synchronization | |
parent | 70fc81c0ab8d35409346d4b2209315a7f30fb306 (diff) | |
download | chromium_src-b3cc0c25614566f1261b9c3759d6a076e327fd6c.zip chromium_src-b3cc0c25614566f1261b9c3759d6a076e327fd6c.tar.gz chromium_src-b3cc0c25614566f1261b9c3759d6a076e327fd6c.tar.bz2 |
Make ConditionVariableTest.MultiThreadConsumerTest less flaky.
Remove the code that tests that Signal() will wake up just one thread.
According to base/synchronization/condition_variable.h, "there can/will be
spurious signals.". One reason for this is explained in the linux man page
for pthread_cond_signal: "The pthread_cond_signal() function shall unblock
*at least one* of the threads" and "On a multi-processor, it may be
impossible for an implementation of pthread_cond_signal() to avoid the
unblocking of more than one thread blocked on a condition variable."
BUG=10607
TEST=ConditionVariableTest.MultiThreadConsumerTest
Review URL: http://codereview.chromium.org/9309055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/synchronization')
-rw-r--r-- | base/synchronization/condition_variable_unittest.cc | 45 |
1 files changed, 1 insertions, 44 deletions
diff --git a/base/synchronization/condition_variable_unittest.cc b/base/synchronization/condition_variable_unittest.cc index d3a53f2..5cc9063 100644 --- a/base/synchronization/condition_variable_unittest.cc +++ b/base/synchronization/condition_variable_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -217,49 +217,6 @@ TEST_F(ConditionVariableTest, MultiThreadConsumerTest) { EXPECT_EQ(0, queue.GetMinCompletionsByWorkerThread()); EXPECT_EQ(0, queue.GetNumberOfCompletedTasks()); - // Set up to make one worker do 30ms tasks sequentially. - queue.ResetHistory(); - queue.SetTaskCount(kTaskCount); - queue.SetWorkTime(kThirtyMs); - queue.SetAllowHelp(false); - - start_time = Time::Now(); - } - - queue.work_is_available()->Signal(); // Start up one thread. - // Wait till we at least start to handle tasks (and we're not all waiting). - queue.SpinUntilTaskCountLessThan(kTaskCount); - - { - // Wait until all 10 work tasks have at least been assigned. - base::AutoLock auto_lock(*queue.lock()); - while (queue.task_count()) - queue.no_more_tasks()->Wait(); - // The last of the tasks *might* still be running, but... all but one should - // be done by now, since tasks are being done serially. - EXPECT_LE(queue.GetWorkTime().InMilliseconds() * (kTaskCount - 1), - (Time::Now() - start_time).InMilliseconds()); - - EXPECT_EQ(1, queue.GetNumThreadsTakingAssignments()); - EXPECT_EQ(1, queue.GetNumThreadsCompletingTasks()); - EXPECT_LE(kTaskCount - 1, queue.GetMaxCompletionsByWorkerThread()); - EXPECT_EQ(0, queue.GetMinCompletionsByWorkerThread()); - EXPECT_LE(kTaskCount - 1, queue.GetNumberOfCompletedTasks()); - } - - // Wait to be sure all tasks are done. - queue.SpinUntilAllThreadsAreWaiting(); - - { - // Check that all work was done by one thread id. - base::AutoLock auto_lock(*queue.lock()); - EXPECT_EQ(1, queue.GetNumThreadsTakingAssignments()); - EXPECT_EQ(1, queue.GetNumThreadsCompletingTasks()); - EXPECT_EQ(0, queue.task_count()); - EXPECT_EQ(kTaskCount, queue.GetMaxCompletionsByWorkerThread()); - EXPECT_EQ(0, queue.GetMinCompletionsByWorkerThread()); - EXPECT_EQ(kTaskCount, queue.GetNumberOfCompletedTasks()); - // Set up to make each task include getting help from another worker, so // so that the work gets done in paralell. queue.ResetHistory(); |