diff options
-rw-r--r-- | tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt | 13 | ||||
-rw-r--r-- | tests/utils/safetycenter/java/com/android/safetycenter/testing/SafetyCenterFlags.kt | 5 |
2 files changed, 15 insertions, 3 deletions
diff --git a/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt b/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt index 44c0686e2..29d1c1f09 100644 --- a/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt +++ b/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt @@ -17,6 +17,7 @@ package com.android.safetycenter.testing import android.util.Log +import androidx.test.platform.app.InstrumentationRegistry import java.time.Duration import kotlinx.coroutines.DEBUG_PROPERTY_NAME import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_AUTO @@ -28,9 +29,19 @@ import kotlinx.coroutines.withTimeoutOrNull /** A class that facilitates interacting with coroutines. */ object Coroutines { + /** + * The timeout of a test case, typically varies depending on whether the test is running + * locally, on pre-submit or post-submit. + */ + val TEST_TIMEOUT: Duration + get() = + Duration.ofMillis( + InstrumentationRegistry.getArguments().getString("timeout_msec", "60000").toLong() + ) /** A long timeout, to be used for actions that are expected to complete. */ - val TIMEOUT_LONG: Duration = Duration.ofSeconds(25) + val TIMEOUT_LONG: Duration + get() = TEST_TIMEOUT.dividedBy(2) /** A short timeout, to be used for actions that are expected not to complete. */ val TIMEOUT_SHORT: Duration = Duration.ofSeconds(1) diff --git a/tests/utils/safetycenter/java/com/android/safetycenter/testing/SafetyCenterFlags.kt b/tests/utils/safetycenter/java/com/android/safetycenter/testing/SafetyCenterFlags.kt index 46b7f5630..f7b5f486d 100644 --- a/tests/utils/safetycenter/java/com/android/safetycenter/testing/SafetyCenterFlags.kt +++ b/tests/utils/safetycenter/java/com/android/safetycenter/testing/SafetyCenterFlags.kt @@ -35,6 +35,7 @@ import android.safetycenter.SafetyCenterManager.REFRESH_REASON_PERIODIC import android.safetycenter.SafetyCenterManager.REFRESH_REASON_RESCAN_BUTTON_CLICK import android.safetycenter.SafetyCenterManager.REFRESH_REASON_SAFETY_CENTER_ENABLED import android.safetycenter.SafetySourceData +import com.android.safetycenter.testing.Coroutines.TEST_TIMEOUT import com.android.safetycenter.testing.Coroutines.TIMEOUT_LONG import com.android.safetycenter.testing.ShellPermissions.callWithShellPermissionIdentity import java.time.Duration @@ -117,7 +118,7 @@ object SafetyCenterFlags { * source to respond to a refresh request before timing out and marking the refresh as finished, * depending on the refresh reason. * - * Unlike the production code, this flag is set to [TIMEOUT_LONG] for all refresh reasons by + * Unlike the production code, this flag is set to [TEST_TIMEOUT] for all refresh reasons by * default for convenience. UI tests typically will set some data manually rather than going * through a full refresh, and we don't want to timeout the refresh and potentially end up with * error entries in this case (as it could lead to flakyness). @@ -125,7 +126,7 @@ object SafetyCenterFlags { private val refreshSourceTimeoutsFlag = Flag( "safety_center_refresh_sources_timeouts_millis", - defaultValue = getAllRefreshTimeoutsMap(TIMEOUT_LONG), + defaultValue = getAllRefreshTimeoutsMap(TEST_TIMEOUT), MapParser(IntParser(), DurationParser()) ) |