From 524256d457391a7bb8b1bfdb8dcfcea0344b2f80 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Tue, 29 Aug 2023 10:22:05 -0700 Subject: [PATCH] ethernet: Wait on releaseTetheredInterface() to be processed There is a race between releaseTetheredInterface() and a new interface being created. Calling setEthernetEnabled(true) forces the test to wait on a callback that is generated on the ethernet handler thread (and therefore guarantees releaseTetheredInterface() has been processed). Bug: 296012516 Test: atest EthernetManagerTest Change-Id: I7a1a763ba5c1c50274a112b8c1b8c04f35696f12 --- tests/cts/net/src/android/net/cts/EthernetManagerTest.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt index 3146b4190c..b7e5205f65 100644 --- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt +++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt @@ -385,6 +385,9 @@ class EthernetManagerTest { } registeredCallbacks.forEach { cm.unregisterNetworkCallback(it) } releaseTetheredInterface() + // Force releaseTetheredInterface() to be processed before starting the next test by calling + // setEthernetEnabled(true) which always waits on a callback. + setEthernetEnabled(true) } // Setting the carrier up / down relies on TUNSETCARRIER which was added in kernel version 5.0. @@ -635,6 +638,9 @@ class EthernetManagerTest { // do nothing -- the TimeoutException indicates that no interface is available for // tethering. releaseTetheredInterface() + // Force releaseTetheredInterface() to be processed before proceeding by calling + // setEthernetEnabled(true) which always waits on a callback. + setEthernetEnabled(true) } }