Fix EthernetTetheringTest flaky
The tracking interface of EthernetTracker(mTetheringInterface) is stopped to track only when it is removed. There is race condition in EthernetTetheringTest that the new test start ethernet tethering with previous test interface name because EthernetTracker still tracking previous test interface. Destroy test interface then listen untether callback without calling stopTethering. If EthernetTracker stop tracking test interface, it would call onUnavailable callback to stop tethering. So the test can check whether tethering is stopped to ensure the test interface is not tracked anymore before test finish. Bug: 191826409 Bug: 243222655 Test: atest TetheringIntegrationTests Change-Id: I618983d981cd3a707dcb7723cdbb20ba5bf8bd2e
This commit is contained in:
@@ -215,26 +215,26 @@ public class EthernetTetheringTest {
|
|||||||
mUpstreamReader = null;
|
mUpstreamReader = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
runAsShell(TETHER_PRIVILEGED, () -> {
|
|
||||||
mTm.stopTethering(TETHERING_ETHERNET);
|
|
||||||
// Binder call is an async call. Need to hold the shell permission until tethering
|
|
||||||
// stopped. This helps to avoid the test become flaky.
|
|
||||||
if (mTetheringEventCallback != null) {
|
|
||||||
mTetheringEventCallback.awaitInterfaceUntethered();
|
|
||||||
mTetheringEventCallback.unregister();
|
|
||||||
mTetheringEventCallback = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (mDownstreamReader != null) {
|
if (mDownstreamReader != null) {
|
||||||
TapPacketReader reader = mDownstreamReader;
|
TapPacketReader reader = mDownstreamReader;
|
||||||
mHandler.post(() -> reader.stop());
|
mHandler.post(() -> reader.stop());
|
||||||
mDownstreamReader = null;
|
mDownstreamReader = null;
|
||||||
}
|
}
|
||||||
runAsShell(NETWORK_SETTINGS, () -> {
|
|
||||||
mTetheredInterfaceRequester.release();
|
// To avoid flaky which caused by the next test started but the previous interface is not
|
||||||
});
|
// untracked from EthernetTracker yet. Just delete the test interface without explicitly
|
||||||
setIncludeTestInterfaces(false);
|
// calling TetheringManager#stopTethering could let EthernetTracker untrack the test
|
||||||
|
// interface from server mode before tethering stopped. Thus, awaitInterfaceUntethered
|
||||||
|
// could not only make sure tethering is stopped but also guarantee the test interface is
|
||||||
|
// untracked from EthernetTracker.
|
||||||
maybeDeleteTestInterface();
|
maybeDeleteTestInterface();
|
||||||
|
if (mTetheringEventCallback != null) {
|
||||||
|
mTetheringEventCallback.awaitInterfaceUntethered();
|
||||||
|
mTetheringEventCallback.unregister();
|
||||||
|
mTetheringEventCallback = null;
|
||||||
|
}
|
||||||
|
runAsShell(NETWORK_SETTINGS, () -> mTetheredInterfaceRequester.release());
|
||||||
|
setIncludeTestInterfaces(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
Reference in New Issue
Block a user