From 70a3384ecccf094e2bc9cca63f0fc76d44659dd9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 23:24:42 +0000 Subject: [PATCH] PppTakeoverTest: wait for the tunnel, and for the link's end The flake (no answer to the echoed packet, then needsACall seeing "it's connected already"): the test sent its packet as soon as openTunnel had the address, but Internet keeps the tunnel openTunnel returns only after it returns, so an echo arriving first had no tunnel to go to and was dropped. It now waits for Internet's state to say connected (set once the tunnel is kept). tearDown waits for the link to finish its hang-up, so a failed test's link can't carry over into the next test. Signed-off-by: Claude Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRRgas5TD8Qpbs8x2NK --- .../org/dmodem/app/android/ppp/PppTakeoverTest.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/org/dmodem/app/android/ppp/PppTakeoverTest.kt b/app/src/test/java/org/dmodem/app/android/ppp/PppTakeoverTest.kt index d93d285..c6d66f7 100644 --- a/app/src/test/java/org/dmodem/app/android/ppp/PppTakeoverTest.kt +++ b/app/src/test/java/org/dmodem/app/android/ppp/PppTakeoverTest.kt @@ -42,10 +42,15 @@ class PppTakeoverTest { ModemState.setStatus(NativeModem.Status(NativeModem.Link.ONLINE, true, 33600, 33600)) } - /** disconnected, the DTE detached, the modem stopped */ + /** + * disconnected (and its hang-up done, so a link left by a failed test + * can't reach the next one's DTE), the DTE detached, the modem stopped + */ @After fun tearDown() { Internet.disconnect() + val end = System.currentTimeMillis() + 15_000 + while (Internet.running && System.currentTimeMillis() < end) Thread.sleep(100) ModemState.dte.detach() ModemState.setStatus(ModemState.IDLE) ModemState.setRun(ModemState.Run.STOPPED) @@ -94,6 +99,11 @@ class PppTakeoverTest { assertEquals("192.168.7.42", cfg.address.hostAddress) // (PPP's frames from the first octet: no AT commands before them) assertEquals('\u007e', synchronized(sent) { sent[0] }) + // (the link's tunnel in place: the address comes to openTunnel before Internet keeps the tunnel + // it returns, and an answer before that would be dropped) + val until = System.currentTimeMillis() + 10_000 + while (Internet.state.value?.connected != true && System.currentTimeMillis() < until) Thread.sleep(20) + assertTrue(Internet.state.value?.connected == true) assertTrue(Internet.sendIp(Ip.udp(cfg.address.address, byteArrayOf(192.toByte(), 168.toByte(), 7, 1), 5353, 7, "hi".toByteArray()))) val back = fromLink.poll(20, TimeUnit.SECONDS) ?: throw AssertionError("no answer")