diff options
author | Elliott Hughes <enh@google.com> | 2017-02-16 17:14:10 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-02-21 14:57:15 -0800 |
commit | 03edc9f7647b3ac9db8a4743acc98b0238b846fb (patch) | |
tree | d71a6b4c41b569f7673f4388ab50cc10b2d97eb3 /base/properties_test.cpp | |
parent | 01815fdcc52e6e94fe078d34ffdd71752e1aafdc (diff) | |
download | system_core-03edc9f7647b3ac9db8a4743acc98b0238b846fb.tar.gz system_core-03edc9f7647b3ac9db8a4743acc98b0238b846fb.tar.bz2 system_core-03edc9f7647b3ac9db8a4743acc98b0238b846fb.zip |
Add timeout support to android::base::WaitForProperty.
Bug: http://b/35201172
Test: ran tests
Change-Id: I025aa0217dc94fabf0eb076b285a84866b00e741
Diffstat (limited to 'base/properties_test.cpp')
-rw-r--r-- | base/properties_test.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/base/properties_test.cpp b/base/properties_test.cpp index d8186be6e..c68c2f805 100644 --- a/base/properties_test.cpp +++ b/base/properties_test.cpp @@ -134,8 +134,19 @@ TEST(properties, WaitForProperty) { android::base::SetProperty("debug.libbase.WaitForProperty_test", "b"); }); - android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "a"); + ASSERT_TRUE(android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "a", 1s)); flag = true; - android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "b"); + ASSERT_TRUE(android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "b", 1s)); thread.join(); } + +TEST(properties, WaitForProperty_timeout) { + auto t0 = std::chrono::steady_clock::now(); + ASSERT_FALSE(android::base::WaitForProperty("debug.libbase.WaitForProperty_timeout_test", "a", + 200ms)); + auto t1 = std::chrono::steady_clock::now(); + + ASSERT_GE(std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0), 200ms); + // Upper bounds on timing are inherently flaky, but let's try... + ASSERT_LT(std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0), 600ms); +} |