RpcClient: wait_for_any, collect_events, call_and_wait #7

Closed
opened 2026-04-11 10:55:38 +00:00 by charles · 0 comments
Owner

User story

As a test author, I want convenience helpers for "wait until done or failed", "collect a stream of progress events", and "send a request and atomically wait for its follow-up event without race", so that the most common test patterns are one-liners.

Acceptance criteria

wait_for_any

  • Signature: wait_for_any(methods: &[&str], predicate: F, timeout: Duration) -> Result<(String, Value), TestError> where F: Fn(&str, &Value) -> bool + Send + Sync.
  • Returns (matched_method, params).
  • Same buffer-then-broadcast strategy as wait_for.
  • On timeout returns TestError::Timeout { event: methods.join("|"), duration }.

collect_events

  • Signature: collect_events(method: &str, duration: Duration) -> Vec<Value>.
  • Drains existing matches from the buffer first, then collects new ones until duration elapses.
  • Never errors on timeout — returns whatever was collected (may be empty).
  • Useful for verifying event streams (e.g., progress goes from 0% to 100%).

call_and_wait

  • Signature:
    call_and_wait(
        method: &str, params: Value,
        event_method: &str, predicate: F, timeout: Duration,
    ) -> Result<(Value, Value), TestError>
    
  • Arms the buffer/listener for event_method before the call is sent, so that an event emitted in response to the call cannot be missed even if it arrives before the call response.
  • Sends the call, waits for the event, returns (call_result, event_params).
  • If the call fails, the listener is torn down and the call error is returned.

General

  • All three methods take &self and are usable from cloned client handles.
  • Each method has a doc test using the mock server.

References

  • Spec §2.5, §2.6, §2.7, §3.2
## User story As a **test author**, I want convenience helpers for "wait until done **or** failed", "collect a stream of progress events", and "send a request and atomically wait for its follow-up event without race", so that the most common test patterns are one-liners. ## Acceptance criteria ### wait_for_any - [ ] Signature: `wait_for_any(methods: &[&str], predicate: F, timeout: Duration) -> Result<(String, Value), TestError>` where `F: Fn(&str, &Value) -> bool + Send + Sync`. - [ ] Returns `(matched_method, params)`. - [ ] Same buffer-then-broadcast strategy as `wait_for`. - [ ] On timeout returns `TestError::Timeout { event: methods.join("|"), duration }`. ### collect_events - [ ] Signature: `collect_events(method: &str, duration: Duration) -> Vec<Value>`. - [ ] Drains existing matches from the buffer first, then collects new ones until `duration` elapses. - [ ] **Never errors on timeout** — returns whatever was collected (may be empty). - [ ] Useful for verifying event streams (e.g., progress goes from 0% to 100%). ### call_and_wait - [ ] Signature: ```rust call_and_wait( method: &str, params: Value, event_method: &str, predicate: F, timeout: Duration, ) -> Result<(Value, Value), TestError> ``` - [ ] Arms the buffer/listener for `event_method` **before** the call is sent, so that an event emitted in response to the call cannot be missed even if it arrives before the call response. - [ ] Sends the call, waits for the event, returns `(call_result, event_params)`. - [ ] If the call fails, the listener is torn down and the call error is returned. ### General - [ ] All three methods take `&self` and are usable from cloned client handles. - [ ] Each method has a doc test using the mock server. ## References - Spec §2.5, §2.6, §2.7, §3.2
charles added this to the v0.1.0 milestone 2026-04-11 10:55:38 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/ws-rpc-test#7
No description provided.