| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file provides a macro ONLY for use in testing. | 5 // This file provides a macro ONLY for use in testing. |
| 6 // DO NOT USE IN PRODUCTION CODE. There are much better ways to wait. | 6 // DO NOT USE IN PRODUCTION CODE. There are much better ways to wait. |
| 7 | 7 |
| 8 // This code is very helpful in testing multi-threaded code, without depending | 8 // This code is very helpful in testing multi-threaded code, without depending |
| 9 // on almost any primitives. This is especially helpful if you are testing | 9 // on almost any primitives. This is especially helpful if you are testing |
| 10 // those primitive multi-threaded constructs. | 10 // those primitive multi-threaded constructs. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // typically used to get the padding needed on a given test platform to assure | 30 // typically used to get the padding needed on a given test platform to assure |
| 31 // that the test passes, even if load varies, and external events vary. | 31 // that the test passes, even if load varies, and external events vary. |
| 32 | 32 |
| 33 #define SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(expression) \ | 33 #define SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(expression) \ |
| 34 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(base::TimeDelta::FromSeconds(1), \ | 34 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(base::TimeDelta::FromSeconds(1), \ |
| 35 (expression)) | 35 (expression)) |
| 36 | 36 |
| 37 #define SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(delta, expression) do { \ | 37 #define SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(delta, expression) do { \ |
| 38 base::Time start = base::Time::Now(); \ | 38 base::Time start = base::Time::Now(); \ |
| 39 const base::TimeDelta kTimeout = delta; \ | 39 const base::TimeDelta kTimeout = delta; \ |
| 40 while(!(expression)) { \ | 40 while (!(expression)) { \ |
| 41 if (kTimeout < base::Time::Now() - start) { \ | 41 if (kTimeout < base::Time::Now() - start) { \ |
| 42 EXPECT_LE((base::Time::Now() - start).InMilliseconds(), \ | 42 EXPECT_LE((base::Time::Now() - start).InMilliseconds(), \ |
| 43 kTimeout.InMilliseconds()) << "Timed out"; \ | 43 kTimeout.InMilliseconds()) << "Timed out"; \ |
| 44 break; \ | 44 break; \ |
| 45 } \ | 45 } \ |
| 46 PlatformThread::Sleep(50); \ | 46 PlatformThread::Sleep(50); \ |
| 47 } \ | 47 } \ |
| 48 } \ | 48 } while (0) |
| 49 while(0) | |
| 50 | 49 |
| 51 #endif // BASE_SPIN_WAIT_H__ | 50 #endif // BASE_SPIN_WAIT_H__ |
| OLD | NEW |