[Thread] Replace the "ot-ctl factoryreset" with the java leave() API

The leave() API can now correctly clear the in-memory state for the
Thread stack, it's better to use the leaveAndWait() API in the tests to
ensure timing sequences

Bug: 338061061
Change-Id: Ic91f8043cd5a35f19b9161c5778f83b83a713946
This commit is contained in:
Kangping Dong 2025-03-04 14:26:43 +08:00
commit cbfe8c938e
4 changed files with 6 additions and 14 deletions

View file

@ -113,8 +113,8 @@ public class ServiceDiscoveryTest {
@Before
public void setUp() throws Exception {
mOtCtl.factoryReset();
mController.setEnabledAndWait(true);
mController.leaveAndWait();
mController.joinAndWait(DEFAULT_DATASET);
mNsdManager = mContext.getSystemService(NsdManager.class);

View file

@ -132,10 +132,6 @@ public class ThreadIntegrationTest {
mOtCtl = new OtDaemonController();
mController.setEnabledAndWait(true);
mController.leaveAndWait();
// TODO: b/323301831 - This is a workaround to avoid unnecessary delay to re-form a network
mOtCtl.factoryReset();
mFtd = new FullThreadDevice(10 /* nodeId */);
}
@ -352,7 +348,6 @@ public class ThreadIntegrationTest {
mOtCtl.executeCommand("netdata register");
mController.leaveAndWait();
mOtCtl.factoryReset();
mController.joinAndWait(DEFAULT_DATASET);
LinkProperties lp = cm.getLinkProperties(getThreadNetwork(CALLBACK_TIMEOUT));

View file

@ -66,11 +66,7 @@ public class ThreadNetworkShellCommandTest {
@Before
public void setUp() throws Exception {
// TODO(b/366141754): The current implementation of "thread_network ot-ctl factoryreset"
// results in timeout error.
// A future fix will provide proper support for factoryreset, allowing us to replace the
// legacy "ot-ctl".
mOtCtl.factoryReset();
mController.leaveAndWait();
mFtd = new FullThreadDevice(10 /* nodeId */);
ensureThreadEnabled();

View file

@ -603,11 +603,12 @@ object IntegrationTestUtils {
/** Enables Thread and joins the specified Thread network. */
@JvmStatic
fun enableThreadAndJoinNetwork(dataset: ActiveOperationalDataset) {
// TODO: b/323301831 - This is a workaround to avoid unnecessary delay to re-form a network
OtDaemonController().factoryReset();
val context: Context = requireNotNull(ApplicationProvider.getApplicationContext());
val controller = requireNotNull(ThreadNetworkControllerWrapper.newInstance(context));
// TODO: b/323301831 - This is a workaround to avoid unnecessary delay to re-form a network
controller.leaveAndWait();
controller.setEnabledAndWait(true);
controller.joinAndWait(dataset);
}