Index: runtime/vm/thread_test.cc |
=================================================================== |
--- runtime/vm/thread_test.cc (revision 14653) |
+++ runtime/vm/thread_test.cc (working copy) |
@@ -39,17 +39,35 @@ |
monitor->Enter(); |
monitor->Exit(); |
- { |
+ const int kNumAttempts = 5; |
+ int attempts = 0; |
+ while (true) { |
MonitorLocker ml(monitor); |
int64_t start = OS::GetCurrentTimeMillis(); |
int64_t wait_time = 2017; |
Monitor::WaitResult wait_result = ml.Wait(wait_time); |
int64_t stop = OS::GetCurrentTimeMillis(); |
+ |
+ // We expect to be timing out here. |
EXPECT_EQ(Monitor::kTimedOut, wait_result); |
+ |
+ // Check whether this attempt falls within the exptected time limits. |
+ int64_t wakeup_time = stop - start; |
+ OS::Print("wakeup_time: %"Pd64"\n", wakeup_time); |
siva
2012/11/07 23:41:02
Is this print statement needed?
Ivan Posva
2012/11/08 18:01:08
It is needed to be able to figure out the wakeup t
|
const int kAcceptableTimeJitter = 20; // Measured in milliseconds. |
- EXPECT_LE(wait_time - kAcceptableTimeJitter, stop - start); |
const int kAcceptableWakeupDelay = 150; // Measured in milliseconds. |
- EXPECT_GE(wait_time + kAcceptableWakeupDelay, stop - start); |
+ if (((wait_time - kAcceptableTimeJitter) <= wakeup_time) && |
+ (wakeup_time <= (wait_time + kAcceptableWakeupDelay))) { |
+ break; |
+ } |
+ |
+ // Record the attempt. |
+ if (attempts++ == kNumAttempts) { |
+ // Ran out of attempts. Record the failure and break out of the loop. |
+ OS::Print("Failed %d consecutive attempts.\n", kNumAttempts); |
siva
2012/11/07 23:41:02
OS::Print("Monitor.wait test failed %d.....
Ivan Posva
2012/11/08 18:01:08
The test harness around it identifies the test. I
|
+ EXPECT(false); |
+ break; |
+ } |
} |
// The isolate shutdown and the destruction of the mutex are out-of-order on |
// purpose. |