Skip to content

Commit

Permalink
Fix ThreadTicks.ThreadNow test on windows
Browse files Browse the repository at this point in the history
The test is flaky because the OS does not sleep for the full requested
time. Adding a check for the OS sleep time.

Bug: v8:7492
Change-Id: I495ecc6595238bc1771adc434e766543513a0256
Reviewed-on: https://chromium-review.googlesource.com/937818
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Fadi Meawad <fmeawad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51774}
  • Loading branch information
fmeawad authored and Commit Bot committed Mar 6, 2018
1 parent 8ca7bd3 commit 1ccbfb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
20 changes: 13 additions & 7 deletions test/unittests/base/platform/time-unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,21 @@ TEST(TimeTicks, IsMonotonic) {
TEST(ThreadTicks, MAYBE_ThreadNow) {
if (ThreadTicks::IsSupported()) {
ThreadTicks::WaitUntilInitialized();
TimeTicks begin = TimeTicks::Now();
ThreadTicks begin_thread = ThreadTicks::Now();
TimeTicks end, begin = TimeTicks::Now();
ThreadTicks end_thread, begin_thread = ThreadTicks::Now();
TimeDelta delta;
// Make sure that ThreadNow value is non-zero.
EXPECT_GT(begin_thread, ThreadTicks());
// Sleep for 10 milliseconds to get the thread de-scheduled.
OS::Sleep(base::TimeDelta::FromMilliseconds(10));
ThreadTicks end_thread = ThreadTicks::Now();
TimeTicks end = TimeTicks::Now();
TimeDelta delta = end - begin;
int iterations_count = 0;
do {
// Sleep for 10 milliseconds to get the thread de-scheduled.
OS::Sleep(base::TimeDelta::FromMilliseconds(10));
end_thread = ThreadTicks::Now();
end = TimeTicks::Now();
delta = end - begin;
EXPECT_LE(++iterations_count, 2); // fail after 2 attempts.
} while (delta.InMicroseconds() <
10000); // Make sure that the OS did sleep for at least 10 ms.
TimeDelta delta_thread = end_thread - begin_thread;
// Make sure that some thread time have elapsed.
EXPECT_GT(delta_thread.InMicroseconds(), 0);
Expand Down
5 changes: 1 addition & 4 deletions test/unittests/unittests.status
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
# found in the LICENSE file.

[
['system == windows', {
# BUG(7492).
'ThreadTicks.ThreadNow': [SKIP],
}], # 'system == windows'

]

0 comments on commit 1ccbfb0

Please sign in to comment.