From ef61c582f50b30bdbd193207a954829f3cdbfc60 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Mon, 15 Aug 2022 21:07:30 -0700 Subject: [PATCH] ethernet: wait for the interface listener to be registered If an interface is created before the interface state listener is registered with the ethernet service, callbacks can get missed. Specifically, createInterface() expects a down before an up callback. If the listener registration executes after the event, the listener only receives the final state event (up in this case). This was a common source of flakiness in the EthernetManagerTests. Test: EthernetManagerTest Change-Id: Iefccc9318a9ea2f929d34a52b7b275bf7a23f443 --- 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 1c92e4e4a2..58c5999fdc 100644 --- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt +++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt @@ -310,6 +310,12 @@ class EthernetManagerTest { fun setUp() { setIncludeTestInterfaces(true) addInterfaceStateListener(ifaceListener) + // Handler.post() events may get processed after native fd events, so it is possible that + // RTM_NEWLINK (from a subsequent createInterface() call) arrives before the interface state + // listener is registered. This affects the callbacks and breaks the tests. + // setEthernetEnabled() will always wait on a callback, so it is used as a barrier to ensure + // proper listener registration before proceeding. + setEthernetEnabled(true) } @After