Skip to content

Assert transport behavior in the heartbeat failure test - #311

Merged
varun06 merged 1 commit into
modelcontextprotocol:mainfrom
akhilcb:oss/heartbeat-test-disable-reconnect
Oct 25, 2026
Merged

varun06 merged 1 commit into
modelcontextprotocol:mainfrom
akhilcb:oss/heartbeat-test-disable-reconnect

Conversation

@akhilcb

@akhilcb akhilcb commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Heartbeat Failure Handling in NetworkTransportTests is flaky and fails CI intermittently
(Expected state to be failed). The test simulates ECONNRESET, sleeps 500 ms, and expects
the connection state to be .failed. That is the state the mock sets itself, so the test
does not check anything the transport did.

After a receive error, the transport marks itself disconnected and, after
backoffDelay(for: 1) (also 500 ms), cancels the connection and tries to reconnect. That
cancel changes the state to .cancelled; when it wins the race against the test's sleep,
the test fails.

The test now checks what the transport does after the failure:

  • it waits, with a timeout, for the transport to cancel the connection, instead of relying
    on a fixed sleep;
  • it then checks that the transport stops sending heartbeats.

Reconnection stays at its default. Disabling it would leave the test checking only the
mock's own state, and the test would fail once #283 cancels the connection when
reconnection is disabled.

How Has This Been Tested?

Breaking Changes

None. Test-only change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

@akhilcb
akhilcb requested a review from a team as a code owner October 24, 2026 22:58
The test simulated ECONNRESET, slept 500 ms, and expected the connection
state to be .failed. That is the state the mock sets itself, so the test
did not check anything the transport did. It was also flaky: the
transport cancels the connection before reconnecting, after
backoffDelay(for: 1), which is also 500 ms, changing the state to
.cancelled. When the cancel won the race, the test failed.

The test now waits, with a timeout, for the transport to cancel the
connection, then checks that it stops sending heartbeats.
@akhilcb
akhilcb force-pushed the oss/heartbeat-test-disable-reconnect branch from a750556 to a3b7a76 Compare October 24, 2026 23:13
@varun06
varun06 merged commit 7627589 into modelcontextprotocol:main Oct 25, 2026
6 checks passed
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.

2 participants