Skip to content

test(linux): cover the spawn-failure reply and the idle/busy read switch - #77

Merged
chaodu-agent merged 1 commit into
mainfrom
test/75-attach-reply-paths
Nov 5, 2026
Merged

chaodu-agent merged 1 commit into
mainfrom
test/75-attach-reply-paths

Conversation

@chaodu-agent

Copy link
Copy Markdown
Contributor

Fixes #75

Adds the two tests left as LOW follow-ups on #72, in poc/reverse-attach-linux/src/attach/liveness_tests.rs.

Tests

  • a_call_thread_that_cannot_start_is_answered_with_an_error: forces the call-thread start to fail. A request gets a JSON-RPC -32603 error with its own id (number and string ids). A notification or a non-JSON frame gets no reply. The in-flight count returns to 0 in every case, so a failed start does not leak the busy count.
  • a_call_queues_its_reply_before_it_stops_counting: applies the socket loop's rule (read the in-flight count, then drain the outbox) to 500 quick calls. Once the count reads zero, the reply must already be queued. This guards the send-before-decrement ordering.
  • a_finished_call_is_answered_before_the_idle_read_timeout: fake runtime with no pings and no client keepalive, and the idle read stretched to 5 s. A sleep 0.3 call must be answered in under 2 s, so a reply that waits for the idle read timeout fails the test.

Refactor for injectability (no behaviour change)

  • spawn_call now delegates to spawn_call_on(text, calls, start). start receives the boxed call job; production passes thread::Builder::spawn, and the test passes a closure that returns an error.
  • DialTuning gains idle_read_poll. Default keeps IDLE_READ_POLL (250 ms), and serve_socket reads it from the tuning instead of the constant.

Verification

  • Raspberry Pi (Debian 13, aarch64): cargo test --release gave 36 passed, 0 failed (33 existing + 3 new).
  • Fail-without-fix on the same host, on a scratch copy that was not committed:
    • Read switch disabled (if false && busy): the idle-timeout test failed (the reply took about 5 s).
    • InFlight dropped before the reply is sent: the queue-order test failed in 5 of 5 runs, and the idle-timeout test failed too.
    • Spawn-failure reply not sent: the spawn-failure test failed.
    • After restoring the code: 36 passed.
  • M4 Mac mini: cargo fmt --check passed, and cargo clippy --release [--all-targets] -- -D warnings was clean.

…tch (#75)

Three tests in src/attach/liveness_tests.rs:

- a_call_thread_that_cannot_start_is_answered_with_an_error: forces the
  call-thread start to fail and asserts a JSON-RPC -32603 error with the
  request's id (number and string), no reply for a notification or non-JSON
  frame, and an in-flight count back at 0 (no busy-count leak).
- a_call_queues_its_reply_before_it_stops_counting: applies the socket
  loop's rule (load the count, then drain) to 500 quick calls; once the
  count reads zero the reply must already be queued.
- a_finished_call_is_answered_before_the_idle_read_timeout: fake runtime,
  idle read stretched to 5 s, no pings or keepalive; a `sleep 0.3` call
  must be answered in under 2 s.

Refactor for injectability (no behaviour change):
- spawn_call delegates to spawn_call_on(text, calls, start), where `start`
  runs the boxed call job; production passes thread::Builder::spawn.
- DialTuning gains idle_read_poll (Default = IDLE_READ_POLL, 250 ms), used
  by serve_socket in place of the constant.

Verification:
- Raspberry Pi (Debian 13 aarch64): cargo test --release -> 36 passed,
  0 failed (33 before + 3 new).
- Fail-without-fix, same host, scratch copy only (not committed):
  - read switch disabled (`if false && busy`): idle-timeout test FAILED
    (reply took ~5 s).
  - InFlight dropped before the reply is sent: queue-order test FAILED
    5/5 runs, idle-timeout test FAILED.
  - spawn-failure reply not sent: spawn-failure test FAILED.
  - restored: 36 passed.
- M4 Mac mini: cargo fmt --check OK; cargo clippy --release
  [--all-targets] -- -D warnings clean.
@chaodu-agent

Copy link
Copy Markdown
Contributor Author

Review: opus5 and sol both LGTM at 40b8b81. CI green (all 7 checks pass), mergeable, merge state CLEAN.

LOW follow-ups (non-blocking):

  • a_call_queues_its_reply_before_it_stops_counting re-implements the loop's load-then-drain rule instead of driving serve_socket, so a swap of drain and load inside serve_socket would almost never be caught.
  • The fail-without-fix mutations were run on an uncommitted scratch copy. Naming the exact mutation (in particular where the InFlight drop was moved) would make the 5/5 result checkable.

@chaodu-agent
chaodu-agent merged commit 6f257c3 into main Nov 5, 2026
7 checks passed
@chaodu-agent chaodu-agent mentioned this pull request Nov 7, 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.

Linux liveness: add tests for spawn_failed_reply and the idle/busy read switch (follow-up to #72)

1 participant