summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJunyu Lai <junyulai@google.com>2021-06-17 08:47:42 +0000
committerJunyu Lai <junyulai@google.com>2021-06-17 08:53:09 +0000
commitad49d71fabe62c3593a891621f0f911f90fba419 (patch)
tree6f47eace34bdc337dc96e3672aa3a2ab9bb7d86d /common
parent30baaa0b24b848e5eb5a20a98cf54362243cd9e6 (diff)
downloadnet-ad49d71fabe62c3593a891621f0f911f90fba419.tar.gz
Allow expect onRequestStatsUpdated with any token
Altough token field is not used for now. But by design, the token will be the version number of networkIdentity mappings that maintain by the service, which cannot be predicted by the test. Thus, allow expecting any token is necessary. Ignore-AOSP-First: Counter part CL is not available in aosp. Test: m gts && atest \ GtsNetworkStackHostTestCases:NetworkStatsHostTest#testNetworkStatsManager Bug: 191327585 Change-Id: Ibf10040a5c10b7b1c7d381c01a071fb157409004
Diffstat (limited to 'common')
-rw-r--r--common/testutils/devicetests/com/android/testutils/TestableNetworkStatsProvider.kt10
1 files changed, 8 insertions, 2 deletions
diff --git a/common/testutils/devicetests/com/android/testutils/TestableNetworkStatsProvider.kt b/common/testutils/devicetests/com/android/testutils/TestableNetworkStatsProvider.kt
index d5c3a2a0..d034a7d5 100644
--- a/common/testutils/devicetests/com/android/testutils/TestableNetworkStatsProvider.kt
+++ b/common/testutils/devicetests/com/android/testutils/TestableNetworkStatsProvider.kt
@@ -23,6 +23,7 @@ import kotlin.test.assertTrue
import kotlin.test.fail
private const val DEFAULT_TIMEOUT_MS = 200L
+const val TOKEN_ANY = -1
open class TestableNetworkStatsProvider(
val defaultTimeoutMs: Long = DEFAULT_TIMEOUT_MS
@@ -49,8 +50,13 @@ open class TestableNetworkStatsProvider(
history.add(CallbackType.OnSetAlert(quotaBytes))
}
- fun expectOnRequestStatsUpdate(token: Int, timeout: Long = defaultTimeoutMs) {
- assertEquals(CallbackType.OnRequestStatsUpdate(token), history.poll(timeout))
+ fun expectOnRequestStatsUpdate(token: Int, timeout: Long = defaultTimeoutMs): Int {
+ val event = history.poll(timeout)
+ assertTrue(event is CallbackType.OnRequestStatsUpdate)
+ if (token != TOKEN_ANY) {
+ assertEquals(token, event.token)
+ }
+ return token
}
fun expectOnSetLimit(iface: String?, quotaBytes: Long, timeout: Long = defaultTimeoutMs) {