Merge "Resolve BasicCallControlsTest flaky tests." into androidx-main
diff --git a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/BasicCallControlsTest.kt b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/BasicCallControlsTest.kt
index 8abbb88..6ca77e6 100644
--- a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/BasicCallControlsTest.kt
+++ b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/BasicCallControlsTest.kt
@@ -17,6 +17,7 @@
package androidx.core.telecom.test
import android.os.Build.VERSION_CODES
+import android.telecom.Call
import android.telecom.DisconnectCause
import androidx.annotation.RequiresApi
import androidx.core.telecom.CallAttributesCompat
@@ -283,11 +284,14 @@
val deferred = CompletableDeferred<Unit>()
assertWithinTimeout_addCall(deferred, callAttributesCompat) {
launch {
+ val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
+ assertNotNull("The returned Call object is <NULL>", call)
if (callAttributesCompat.isOutgoingCall()) {
assertTrue(setActive())
} else {
assertTrue(answer(CallAttributesCompat.CALL_TYPE_AUDIO_CALL))
}
+ TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE)
assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL)))
deferred.complete(Unit) // completed all asserts. cancel timeout!
}
@@ -301,9 +305,13 @@
val deferred = CompletableDeferred<Unit>()
assertWithinTimeout_addCall(deferred, callAttributesCompat) {
launch {
+ val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
+ assertNotNull("The returned Call object is <NULL>", call)
repeat(NUM_OF_TIMES_TO_TOGGLE) {
assertTrue(setActive())
+ TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE)
assertTrue(setInactive())
+ TestUtils.waitOnCallState(call, Call.STATE_HOLDING)
}
assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL)))
deferred.complete(Unit) // completed all asserts. cancel timeout!
@@ -317,7 +325,10 @@
val deferred = CompletableDeferred<Unit>()
assertWithinTimeout_addCall(deferred, callAttributesCompat) {
launch {
+ val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
+ assertNotNull("The returned Call object is <NULL>", call)
assertTrue(setActive())
+ TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE)
assertFalse(setInactive()) // API under test / expect failure
assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL)))
deferred.complete(Unit) // completed all asserts. cancel timeout!
@@ -371,7 +382,10 @@
val deferred = CompletableDeferred<Unit>()
assertWithinTimeout_addCall(deferred, TestUtils.OUTGOING_CALL_ATTRIBUTES) {
launch {
+ val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
+ assertNotNull("The returned Call object is <NULL>", call)
assertTrue(setActive())
+ TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE)
// Grab initial mute state
val initialMuteState = isMuted.first()
// Toggle to other state