From 7d48e98d33b583a4a30b151febcbe18395823e48 Mon Sep 17 00:00:00 2001 From: Compot Developer Date: Tue, 20 Oct 2026 09:17:41 +0000 Subject: [PATCH] test: UdpHeartbeatTest waits for the sent count instead of racing it (#247) The heartbeat counts a packet after send() returns; the toy socket may get it before that, so the count could still be 3 after the 4th packet. --- .../src/test/java/com/openipc/decoder/UdpHeartbeatTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/app/src/test/java/com/openipc/decoder/UdpHeartbeatTest.java b/android/app/src/test/java/com/openipc/decoder/UdpHeartbeatTest.java index 5004a161..29ef1ef8 100644 --- a/android/app/src/test/java/com/openipc/decoder/UdpHeartbeatTest.java +++ b/android/app/src/test/java/com/openipc/decoder/UdpHeartbeatTest.java @@ -99,7 +99,10 @@ public void sendsOneOneEverySecondUntilClosed() throws Exception { // About one interval apart: the scheduler neither bursts nor stalls long span = at[at.length - 1] - at[0]; assertTrue("span " + span, span >= 3 * 100 - 40 && span < 3 * 100 + 400); - assertTrue(h.sent() >= 4); + // The count goes up after send() returns, maybe after the toy got the packet (#247) + long until = System.nanoTime() / 1_000_000 + 1000; + while (h.sent() < 4 && System.nanoTime() / 1_000_000 < until) Thread.sleep(5); + assertTrue("sent " + h.sent(), h.sent() >= 4); h.close(); assertFalse(h.running()); // What was on its way is read; then nothing more