Skip to content

test(sdk): reproduce client lifecycle bugs - #4344

Merged
mmodzelewski merged 6 commits into
apache:masterfrom
TomPlanche:test/sdk-client-lifecycle
Oct 1, 2026
Merged

mmodzelewski merged 6 commits into
apache:masterfrom
TomPlanche:test/sdk-client-lifecycle

Conversation

@TomPlanche

@TomPlanche TomPlanche commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

edit: the TODOs now follow the design agreed with the maintainers: a caller-intent flag for disconnect(), and one guard in set_state for Shutdown.
edit2: after the automated review, the auto-login clients come from connection strings with a zero reconnect cooldown, the heartbeat test runs on TCP, WebSocket and QUIC (13 cases instead of 11), and each ignore reason says how to run the test. The QUIC heartbeat case also reproduces problem 8, so disconnect() is bounded to fail instead of hang.
edit3: after the review of @hubcio, the ping and get_stats tests are one test (10 cases instead of 13), the assertions pin NotConnected and Disconnected and print the value they got, the helper formats one connection string for every transport, and the TODOs name the Python files that each fix must update.

Which issue does this PR address?

Relates to #4287 (tests for problems 1 to 4)

Rationale

The Rust SDK does not keep the lifecycle contract of its clients. A client that is shut down can connect again, and an explicit disconnect() does not hold until the next connect(). As agreed on #4287 and on Discord, the first step is to prove these bugs with failing tests. The #[ignore] reasons keep a trace in the code that the lifecycle is broken until the fixes land.

What changed?

No test covered what happens after shutdown() or after an explicit disconnect() with auto-login credentials. core/integration/tests/sdk/client_lifecycle.rs now pins the expected behavior in four tests (10 cases), all marked #[ignore] because they fail on the current SDK:

  • Problem 1: a WebSocket client that is shut down must not connect again.
  • Problem 2: with auto-login, the heartbeat must not undo an explicit disconnect(), on TCP, WebSocket and QUIC.
  • Problem 3: after disconnect(), ping() and then get_stats() must fail with NotConnected on the SDK side at once, without a reconnect, on TCP, WebSocket and QUIC. One test sends both requests, so it also catches a fix that stops only the first request.
  • Problem 4: after shutdown(), disconnect() must keep the client shut down, on TCP, WebSocket and QUIC.

The auto-login clients come from connection strings with a zero reconnect cooldown, so no reconnect hides behind a pause. Each ignore reason says how to run the test.

The heartbeat test also reproduces problem 8 on QUIC. A heartbeat redial blocks disconnect() in endpoint.wait_idle(), and the call never returns. The test bounds disconnect() to 5 s, so this case fails instead of hanging. The hang depends on timing: the redial must land inside the drain of the old connection. When it misses, the QUIC case fails on the heartbeat assertion instead, as TCP and WebSocket do.

Each test carries the suggested fix in a TODO. A fix PR applies the TODO and removes the #[ignore] of the tests that it fixes. This PR does not cover problems 5 to 7, because they are races that need fault injection to reproduce reliably.

Local Execution

I used Zed in devcontainer mode. The build and the tests ran in the devcontainer, and prek ran on macOS.

  • Passed: cargo fmt --all and cargo clippy -p integration --all-features --all-targets -- -D warnings.

  • Passed: a normal run ignores the 10 cases, so CI stays green:

    $ cargo test -p integration -- sdk::client_lifecycle
    test result: ok. 0 passed; 0 failed; 10 ignored; 0 measured; 974 filtered out
    
  • Passed: with --ignored, the 10 cases fail, each on its own assertion, with the value it got:

    $ cargo test -p integration -- --ignored sdk::client_lifecycle
    given_a_shut_down_websocket_client_when_connecting_should_fail
        => a client that is shut down must not open a new connection, got Ok(())
    given_a_shut_down_client_when_disconnected_should_stay_shut_down::{tcp,websocket,quic}
        => disconnect after shutdown must not make the client reusable, got Ok(())
    given_an_auto_login_client_when_explicitly_disconnected_should_stay_disconnected::{tcp,websocket}
        => a heartbeat after an explicit disconnect must not reconnect the client and replay its auto-login, got Ok(())
    given_an_auto_login_client_when_explicitly_disconnected_should_stay_disconnected::quic
        => disconnect must return while the heartbeat runs: Elapsed(())
    given_a_disconnected_auto_login_client_when_sending_requests_should_fail_without_reconnecting::{tcp,websocket,quic}
        => ping after an explicit disconnect must fail at once, without a reconnect, got Ok(Ok(()))
    test result: FAILED. 0 passed; 10 failed; 0 ignored; 0 measured; 974 filtered out
    
  • Passed: the heartbeat test fails on all three transports in 3 out of 3 runs.

  • Passed: pre-commit hooks with SKIP=web-lint prek run --all-files. I skipped web-lint because this PR does not change web/.

AI Usage

  1. Still no ^^

@github-actions

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Sep 29, 2026
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.59%. Comparing base (ed6e6e7) to head (8532100).

Additional details and impacted files
@@              Coverage Diff              @@
##             master    #4344       +/-   ##
=============================================
- Coverage     87.84%   54.59%   -33.26%     
  Complexity     1577     1577               
=============================================
  Files          1290     1287        -3     
  Lines        228835   182436    -46399     
  Branches     192195   145796    -46399     
=============================================
- Hits         201015    99595   -101420     
- Misses        23092    78209    +55117     
+ Partials       4728     4632       -96     
Components Coverage Δ
Rust Core 46.95% <ø> (-41.99%) ⬇️
Java SDK 68.73% <ø> (ø)
C# SDK 77.44% <ø> (ø)
Python SDK 91.24% <ø> (ø)
PHP SDK 85.67% <ø> (ø)
Node SDK 96.57% <ø> (ø)
Go SDK 70.30% <ø> (ø)
see 501 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TomPlanche

Copy link
Copy Markdown
Contributor Author

/request-review @hubcio @jiengup

@github-actions

Copy link
Copy Markdown

/request-review: could not request hubcio, jiengup - a handle is not a repo collaborator, or the team is unknown.

@hubcio

hubcio commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

/skill team-review-slim

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: Review of a test-only change that adds five #[ignore]​d SDK lifecycle tests for #4287: WebSocket connect after shutdown, disconnect after shutdown, and the heartbeat and request paths that undo an explicit disconnect. The heartbeat test cannot fail on the current SDK, because get_me() answers from the local auth state while the heartbeat's redial waits out its cooldown, and CI compiles these tests but never runs them, so every finding here comes from reading the checkout.

Counts: critical 0, warning 1, nit 1, simplification 1


This review was generated by Claude Code 2.1.284 on deepseek-flash[1m]. Review the output before you act on it.

@github-actions github-actions Bot added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Sep 29, 2026
@TomPlanche

Copy link
Copy Markdown
Contributor Author

/ready

@github-actions github-actions Bot added S-waiting-on-review PR is waiting on a reviewer and removed S-waiting-on-author PR is waiting on author response labels Sep 29, 2026
@TomPlanche

Copy link
Copy Markdown
Contributor Author

/request-review @hubcio

@github-actions
github-actions Bot requested a review from hubcio September 30, 2026 10:48

@hubcio hubcio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Client::shutdown at core/common/src/traits/client.rs:54 has only a plain // comment, and neither trait method states the lifecycle contract these tests pin. the fix PR is a good place to document it on the trait.

@github-actions github-actions Bot added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Sep 30, 2026
@TomPlanche

Copy link
Copy Markdown
Contributor Author

nit: Client::shutdown at core/common/src/traits/client.rs:54 has only a plain // comment, and neither trait method states the lifecycle contract these tests pin. the fix PR is a good place to document it on the trait.

Agreed, I will document the lifecycle contract on the Client trait in the fix PR.

@TomPlanche

Copy link
Copy Markdown
Contributor Author

/ready

@TomPlanche
TomPlanche requested a review from hubcio September 30, 2026 13:02
@github-actions github-actions Bot added S-waiting-on-review PR is waiting on a reviewer and removed S-waiting-on-author PR is waiting on author response labels Sep 30, 2026
@TomPlanche
TomPlanche force-pushed the test/sdk-client-lifecycle branch from 9a0be2c to 2f26941 Compare September 30, 2026 13:04
@mmodzelewski
mmodzelewski merged commit a08d0ca into apache:master Oct 1, 2026
82 of 99 checks passed
@github-actions github-actions Bot removed the S-waiting-on-review PR is waiting on a reviewer label Oct 1, 2026
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.

4 participants