diff options
| author | Dianne Hackborn <hackbod@google.com> | 2009-09-17 08:42:13 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2009-09-17 08:42:13 -0700 |
| commit | ca1475a868c6fe24700065a8ae321bb41425c033 (patch) | |
| tree | e531c79f70f3f93a40a09aa3e863ae7ce6d90ac7 /tests | |
| parent | 3ce9730848f5e1b0ab277eb77932fe60b888b2fd (diff) | |
| parent | 8843620cb208904bb9583809c9cfbe9e41264ae0 (diff) | |
| download | frameworks_base-ca1475a868c6fe24700065a8ae321bb41425c033.zip frameworks_base-ca1475a868c6fe24700065a8ae321bb41425c033.tar.gz frameworks_base-ca1475a868c6fe24700065a8ae321bb41425c033.tar.bz2 | |
am 8843620c: Merge change 25360 into eclair
Merge commit '8843620cb208904bb9583809c9cfbe9e41264ae0' into eclair-plus-aosp
* commit '8843620cb208904bb9583809c9cfbe9e41264ae0':
Fix issue #2121993: com.android.unit_tests.os.HandlerThreadTest:testHandlerThread is failing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/AndroidTests/src/com/android/unit_tests/os/HandlerThreadTest.java | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/os/HandlerThreadTest.java b/tests/AndroidTests/src/com/android/unit_tests/os/HandlerThreadTest.java index c62f94f..f2025c6 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/os/HandlerThreadTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/os/HandlerThreadTest.java @@ -36,8 +36,11 @@ public class HandlerThreadTest extends TestCase { public void testHandlerThread() throws Exception { HandlerThread th1 = new HandlerThread("HandlerThreadTest") { protected void onLooperPrepared() { - mDidSetup = true; - mLooperTid = Process.myTid(); + synchronized (HandlerThreadTest.this) { + mDidSetup = true; + mLooperTid = Process.myTid(); + HandlerThreadTest.this.notify(); + } } }; @@ -49,14 +52,23 @@ public class HandlerThreadTest extends TestCase { assertTrue(th1.isAlive()); assertNotNull(th1.getLooper()); - /* - * Since getLooper() will block until the HandlerThread is setup, we are guaranteed - * that mDidSetup and mLooperTid will have been initalized. If they have not, then - * this test should fail - */ + // The call to getLooper() internally blocks until the looper is + // available, but will call onLooperPrepared() after that. So we + // need to block here to wait for our onLooperPrepared() to complete + // and fill in the values we expect. + synchronized (this) { + while (!mDidSetup) { + try { + wait(); + } catch (InterruptedException e) { + } + } + } + + // Make sure that the process was set. + assertNotSame(-1, mLooperTid); // Make sure that the onLooperPrepared() was called on a different thread. assertNotSame(Process.myTid(), mLooperTid); - assertTrue(mDidSetup); final Handler h1 = new Handler(th1.getLooper()) { public void handleMessage(Message msg) { |
