Skip to content

test: UdpHeartbeatTest no longer races the sent count (#247) - #249

Merged
compot-dev merged 1 commit into
v2from
test/heartbeat-flaky-247
Oct 20, 2026
Merged

compot-dev merged 1 commit into
v2from
test/heartbeat-flaky-247

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #247.

UdpHeartbeat counts a packet after send() returns, and the test's toy socket can get the datagram before that, so assertTrue(h.sent() >= 4) right after the 4th receive() failed now and then (2 of 4 local runs). The test now waits up to 1 s for the count and prints it on failure.

Test-only: no new version (the version check skips android/app/src/test).

  • Docker build as CI: testDebugUnitTest (359 tests), lintDebug, assembleDebug; UdpHeartbeatTest alone 6 runs in a row, all pass

…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.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Prevent a sent-count race in UdpHeartbeatTest

🧪 Tests 🐞 Bug fix 🕐 Less than 5 minutes

Grey Divider

AI Description

• Wait up to one second for the heartbeat's sent count after receiving four datagrams.
• Include the observed count in assertion failures to help diagnose future test failures.
Diagram

sequenceDiagram
    participant H as Heartbeat thread
    participant S as UDP socket
    participant T as Test thread
    H->>S: Send heartbeat
    S->>T: Deliver fourth datagram
    H->>H: Increment sent count
    T->>H: Poll sent count
    H-->>T: Count at least four
    T->>T: Assert count
Loading
High-Level Assessment

Keep the bounded wait in the test. It accommodates the existing ordering between datagram delivery and counter increment without changing production behavior; an immediate assertion cannot reliably establish that the count has caught up.

Files changed (1) +4 / -1

Tests (1) +4 / -1
UdpHeartbeatTest.javaWait for the fourth heartbeat to appear in the sent count +4/-1

Wait for the fourth heartbeat to appear in the sent count

• Replaces the immediate sent-count assertion with polling at five-millisecond intervals for up to one second. The assertion reports the observed count if the wait expires.

android/app/src/test/java/com/openipc/decoder/UdpHeartbeatTest.java

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can open the rule or relationship behind a finding in one click

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev
compot-dev merged commit df27c3c into v2 Oct 20, 2026
7 checks passed
@compot-dev
compot-dev deleted the test/heartbeat-flaky-247 branch October 20, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky unit test: UdpHeartbeatTest reads the sent count before it is updated

1 participant