Testing that waiting for a condition variable waits.

Added a test that verifies that waiting for a condition variable
actually waits for a non-zero time.

This used to fail due to a TSAN / CLANG bug, but this failure
is supposed to have been fixed.

This was originally https://webrtc-codereview.appspot.com/2145004

BUG=2259

Review URL: https://codereview.webrtc.org/1416873002

Cr-Commit-Position: refs/heads/master@{#10341}
diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc
index c34c4ea..6e8a1ec 100644
--- a/webrtc/system_wrappers/source/condition_variable_unittest.cc
+++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc
@@ -11,8 +11,10 @@
 #include "webrtc/system_wrappers/interface/condition_variable_wrapper.h"
 
 #include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/interface/thread_wrapper.h"
+#include "webrtc/system_wrappers/interface/tick_util.h"
 #include "webrtc/system_wrappers/interface/trace.h"
 
 namespace webrtc {
@@ -21,6 +23,7 @@
 
 const int kLongWaitMs = 100 * 1000; // A long time in testing terms
 const int kShortWaitMs = 2 * 1000; // Long enough for process switches to happen
+const int kVeryShortWaitMs = 20; // Used when we want a timeout
 
 // A Baton is one possible control structure one can build using
 // conditional variables.
@@ -184,6 +187,19 @@
   EXPECT_EQ(2 * kNumberOfRounds, baton_.PassCount());
 }
 
+TEST(CondVarWaitTest, WaitingWaits) {
+  rtc::scoped_ptr<CriticalSectionWrapper> crit_sect(
+      CriticalSectionWrapper::CreateCriticalSection());
+  rtc::scoped_ptr<ConditionVariableWrapper> cond_var(
+      ConditionVariableWrapper::CreateConditionVariable());
+  CriticalSectionScoped cs(crit_sect.get());
+  int64_t start_ms = TickTime::MillisecondTimestamp();
+  EXPECT_FALSE(cond_var->SleepCS(*(crit_sect), kVeryShortWaitMs));
+  int64_t end_ms = TickTime::MillisecondTimestamp();
+  EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms)
+      << "actual elapsed:" << end_ms - start_ms;
+}
+
 }  // anonymous namespace
 
 }  // namespace webrtc