summaryrefslogtreecommitdiff
path: root/InCallUI/tests
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-02-12 17:47:41 -0800
committerBrandon Maxwell <maxwelb@google.com>2016-02-12 18:36:41 -0800
commit90820a50b614e8b5f6a9830536553167e1914faa (patch)
tree57021a2dbc4aeeec4d6750bba204def94a5a4275 /InCallUI/tests
parent054559b6c279a0149ac6473d1897f6db817c5a57 (diff)
Added ackAllMilestones api to PausableExecutor
+ This API simplifies tests, specifically their tearDown methods. Rather than needing to call ackMilestone numerous times to clean up at the end of the test, this method can be called to ensure that the thread running the production code isn't blocked on the tests. Change-Id: I60730c52491b315aee571f4ae158f62d34b0dbc2
Diffstat (limited to 'InCallUI/tests')
-rw-r--r--InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java11
-rw-r--r--InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java7
2 files changed, 11 insertions, 7 deletions
diff --git a/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java b/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java
index 839bb2e96..5717c9478 100644
--- a/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java
+++ b/InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java
@@ -30,12 +30,13 @@ public final class SingleProdThreadExecutor implements PausableExecutor {
private int mMilestonesReached;
private int mMilestonesAcked;
+ private boolean mHasAckedAllMilestones;
@Override
public synchronized void milestone() {
++mMilestonesReached;
notify();
- while (mMilestonesReached > mMilestonesAcked) {
+ while (!mHasAckedAllMilestones && mMilestonesReached > mMilestonesAcked) {
try {
wait();
} catch (InterruptedException e) {}
@@ -49,8 +50,14 @@ public final class SingleProdThreadExecutor implements PausableExecutor {
}
@Override
+ public synchronized void ackAllMilestonesForTesting() {
+ mHasAckedAllMilestones = true;
+ notify();
+ }
+
+ @Override
public synchronized void awaitMilestoneForTesting() throws InterruptedException {
- while (mMilestonesReached <= mMilestonesAcked) {
+ while (!mHasAckedAllMilestones && mMilestonesReached <= mMilestonesAcked) {
wait();
}
}
diff --git a/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java b/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java
index 096d21122..59611f701 100644
--- a/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java
+++ b/InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java
@@ -61,11 +61,8 @@ public class InCallTonePlayerTest extends AndroidTestCase {
super.tearDown();
// Stop any playing so the InCallTonePlayer isn't stuck waiting for the tone to complete
mInCallTonePlayer.stop();
- // 3 milestones in InCallTonePlayer, ack them to ensure that the prod thread doesn't block
- // forever. It's fine to ack for more milestones than are hit
- mExecutor.ackMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
- mExecutor.ackMilestoneForTesting();
+ // Ack all milestones to ensure that the prod thread doesn't block forever
+ mExecutor.ackAllMilestonesForTesting();
}
public void testIsPlayingTone_False() {