Unify the verification for unregister a NetworkAgent
It's a follow up of aosp/1652210. The tests may verify partial NetworkAgent callback behavior. The existing expectCallback will always expect to see the first callback in the callback queue, so if tests did not verify all the happened callback. It cannot verify the callback after unregister. Add eventuallyExpect to wait for a target callback and skip the disinterest ones, and verify the unregister behavior for NetworkAgent callback in one method. Bug: 178725261 Test: atest android.net.cts.NetworkAgentTest Change-Id: I66d8e5a0fa1e2245711e8ac90d9daca24802e399
This commit is contained in:
@@ -300,6 +300,11 @@ class NetworkAgentTest {
|
|||||||
return foundCallback
|
return foundCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : CallbackEntry> eventuallyExpect() =
|
||||||
|
history.poll(DEFAULT_TIMEOUT_MS) { it is T }.also {
|
||||||
|
assertNotNull(it, "Callback ${T::class} not received")
|
||||||
|
} as T
|
||||||
|
|
||||||
fun assertNoCallback() {
|
fun assertNoCallback() {
|
||||||
assertTrue(waitForIdle(DEFAULT_TIMEOUT_MS),
|
assertTrue(waitForIdle(DEFAULT_TIMEOUT_MS),
|
||||||
"Handler didn't became idle after ${DEFAULT_TIMEOUT_MS}ms")
|
"Handler didn't became idle after ${DEFAULT_TIMEOUT_MS}ms")
|
||||||
@@ -376,13 +381,12 @@ class NetworkAgentTest {
|
|||||||
callback.expectAvailableThenValidatedCallbacks(agent.network)
|
callback.expectAvailableThenValidatedCallbacks(agent.network)
|
||||||
agent.expectEmptySignalStrengths()
|
agent.expectEmptySignalStrengths()
|
||||||
agent.expectNoInternetValidationStatus()
|
agent.expectNoInternetValidationStatus()
|
||||||
agent.unregister()
|
|
||||||
|
unregister(agent)
|
||||||
callback.expectCallback<Lost>(agent.network)
|
callback.expectCallback<Lost>(agent.network)
|
||||||
agent.expectCallback<OnNetworkUnwanted>()
|
|
||||||
assertFailsWith<IllegalStateException>("Must not be able to register an agent twice") {
|
assertFailsWith<IllegalStateException>("Must not be able to register an agent twice") {
|
||||||
agent.register()
|
agent.register()
|
||||||
}
|
}
|
||||||
agent.expectCallback<OnNetworkDestroyed>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -393,7 +397,7 @@ class NetworkAgentTest {
|
|||||||
agent.expectNoInternetValidationStatus()
|
agent.expectNoInternetValidationStatus()
|
||||||
mCM.requestBandwidthUpdate(agent.network)
|
mCM.requestBandwidthUpdate(agent.network)
|
||||||
agent.expectCallback<OnBandwidthUpdateRequested>()
|
agent.expectCallback<OnBandwidthUpdateRequested>()
|
||||||
agent.unregister()
|
unregister(agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -635,10 +639,16 @@ class NetworkAgentTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.unregister()
|
unregister(agent)
|
||||||
callback.expectCallback<Lost>(agent.network)
|
callback.expectCallback<Lost>(agent.network)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun unregister(agent: TestableNetworkAgent) {
|
||||||
|
agent.unregister()
|
||||||
|
agent.eventuallyExpect<OnNetworkUnwanted>()
|
||||||
|
agent.eventuallyExpect<OnNetworkDestroyed>()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IgnoreUpTo(Build.VERSION_CODES.R)
|
@IgnoreUpTo(Build.VERSION_CODES.R)
|
||||||
fun testAgentStartsInConnecting() {
|
fun testAgentStartsInConnecting() {
|
||||||
|
|||||||
Reference in New Issue
Block a user