Merge "Refactor: Fix lint errors in EthernetManagerTest" into main

This commit is contained in:
Patrick Rohr 2025-07-01 08:23:06 -07:00 • committed by Android (Google) Code Review
commit efc0d104e3

View file

@ -70,12 +70,12 @@ import com.android.testutils.DevSdkIgnoreRule
import com.android.testutils.DevSdkIgnoreRunner
import com.android.testutils.DeviceInfoUtils.isKernelVersionAtLeast
import com.android.testutils.NdResponder
import com.android.testutils.PollPacketReader
import com.android.testutils.TestableNetworkCallback
import com.android.testutils.TestableNetworkCallback.Event.Available
import com.android.testutils.TestableNetworkCallback.Event.CapabilitiesChanged
import com.android.testutils.TestableNetworkCallback.Event.LinkPropertiesChanged
import com.android.testutils.TestableNetworkCallback.Event.Lost
import com.android.testutils.PollPacketReader
import com.android.testutils.TestableNetworkCallback
import com.android.testutils.assertThrows
import com.android.testutils.runAsShell
import com.android.testutils.waitForIdle
@ -104,17 +104,23 @@ import org.junit.Test
import org.junit.runner.RunWith
private const val TAG = "EthernetManagerTest"
// This timeout does not affect the test duration for passing tests. It needs to be long enough to
// account for RS delay (and potentially the first retry interval (4s)). There have been failures
// where the interface did not gain provisioning within the allotted timeout.
private const val TIMEOUT_MS = 10_000L
// Timeout used to confirm no callbacks matching given criteria are received. Must be long enough to
// process all callbacks including ip provisioning when using the updateConfiguration API.
// Note that increasing this timeout increases the test duration.
private const val NO_CALLBACK_TIMEOUT_MS = 500L
private val DEFAULT_IP_CONFIGURATION = IpConfiguration(IpConfiguration.IpAssignment.DHCP,
IpConfiguration.ProxySettings.NONE, null, null)
private val DEFAULT_IP_CONFIGURATION = IpConfiguration(
IpConfiguration.IpAssignment.DHCP,
IpConfiguration.ProxySettings.NONE,
null,
null
)
private val ETH_REQUEST: NetworkRequest = NetworkRequest.Builder()
.addTransportType(TRANSPORT_TEST)
.addTransportType(TRANSPORT_ETHERNET)
@ -287,8 +293,12 @@ class EthernetManagerTest {
}
private fun createChangeEvent(iface: String, state: Int, role: Int) =
InterfaceStateChanged(iface, state, role,
if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null)
InterfaceStateChanged(
iface,
state,
role,
if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null
)
fun eventuallyExpect(expected: Event) {
val cb = events.poll(TIMEOUT_MS) { it == expected }
@ -468,7 +478,8 @@ class EthernetManagerTest {
private fun requestNetwork(request: NetworkRequest): TestableNetworkCallback {
return TestableNetworkCallback(
timeoutMs = TIMEOUT_MS,
noCallbackTimeoutMs = NO_CALLBACK_TIMEOUT_MS).also {
noCallbackTimeoutMs = NO_CALLBACK_TIMEOUT_MS
).also {
cm.requestNetwork(request, it)
registeredCallbacks.add(it)
}
@ -477,7 +488,8 @@ class EthernetManagerTest {
private fun registerNetworkListener(request: NetworkRequest): TestableNetworkCallback {
return TestableNetworkCallback(
timeoutMs = TIMEOUT_MS,
noCallbackTimeoutMs = NO_CALLBACK_TIMEOUT_MS).also {
noCallbackTimeoutMs = NO_CALLBACK_TIMEOUT_MS
).also {
cm.registerNetworkCallback(request, it)
registeredCallbacks.add(it)
}
@ -525,7 +537,8 @@ class EthernetManagerTest {
.setIpConfiguration(ipConfig)
.setNetworkCapabilities(capabilities).build(),
handler::post,
it)
it
)
}
}
@ -1112,7 +1125,6 @@ class EthernetManagerTest {
listener.eventuallyExpect(iface, STATE_LINK_UP, ROLE_CLIENT)
}
@Test
fun testRemoveInterface_disableEnableEthernet() {
// Set up 2 interfaces for testing