summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-02-13 02:58:44 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-02-13 02:58:44 +0000
commit4d699dee102231b0f1e859f62dbb13f914076125 (patch)
tree22f440e2b5cb20ab0970cb6e9d3438f01e716bc5
parent9a6712c3c2edc713a4d4e6657a8e51f4cb8f382e (diff)
parentc677fc15403996055d2c6fa73e7ff0928bd218b9 (diff)
Added ackAllMilestones api to PausableExecutor am: 90820a50b6
am: c677fc1540 * commit 'c677fc15403996055d2c6fa73e7ff0928bd218b9': Added ackAllMilestones api to PausableExecutor
-rw-r--r--InCallUI/src/com/android/incallui/async/PausableExecutor.java8
-rw-r--r--InCallUI/src/com/android/incallui/async/PausableExecutorImpl.java3
-rw-r--r--InCallUI/tests/src/com/android/incallui/async/SingleProdThreadExecutor.java11
-rw-r--r--InCallUI/tests/src/com/android/incallui/ringtone/InCallTonePlayerTest.java7
4 files changed, 22 insertions, 7 deletions
diff --git a/InCallUI/src/com/android/incallui/async/PausableExecutor.java b/InCallUI/src/com/android/incallui/async/PausableExecutor.java
index fdeef360c..1b8201a79 100644
--- a/InCallUI/src/com/android/incallui/async/PausableExecutor.java
+++ b/InCallUI/src/com/android/incallui/async/PausableExecutor.java
@@ -45,6 +45,14 @@ public interface PausableExecutor extends Executor {
void ackMilestoneForTesting();
/**
+ * Method called from the test code to inform this executor that the tests are finished with all
+ * milestones. Future calls to {@link #milestone()} or {@link #awaitMilestoneForTesting()}
+ * should return immediately.
+ */
+ @NeededForTesting
+ void ackAllMilestonesForTesting();
+
+ /**
* Method called from the test code to block until a milestone has been reached in the
* production code.
*/
diff --git a/InCallUI/src/com/android/incallui/async/PausableExecutorImpl.java b/InCallUI/src/com/android/incallui/async/PausableExecutorImpl.java
index e493feb3d..15900e57b 100644
--- a/InCallUI/src/com/android/incallui/async/PausableExecutorImpl.java
+++ b/InCallUI/src/com/android/incallui/async/PausableExecutorImpl.java
@@ -30,6 +30,9 @@ public class PausableExecutorImpl implements PausableExecutor {
public void ackMilestoneForTesting() {}
@Override
+ public void ackAllMilestonesForTesting() {}
+
+ @Override
public void awaitMilestoneForTesting() {}
@Override
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() {