feat(client): wait_for_any, collect_events, call_and_wait (#7) #25
No reviewers
Labels
No labels
area:assertions
area:cli
area:client
area:harness
area:meta
area:reporting
area:runner
type:user-story
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/ws-rpc-test!25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/7-multi-event-helpers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #7. Stacked on #24.
Summary
Three convenience helpers on top of
wait_forthat cover the most common test patterns.wait_for_any(methods, predicate, timeout)(matched_method: String, params: Value).Fn(&str, &Value) -> boolso it can branch on the matched method.wait_for. Newdrain_first_any/try_drain_notification_anyhelpers handle the multi-method scan atomically.methods.join("|").collect_events(method, duration)durationelapses, draining matches on each wake-up.call_and_wait(method, params, event_method, predicate, timeout)(call_result, event_params).Checklist (from issue #7)
wait_for_any
(methods, F: Fn(&str, &Value) -> bool, timeout) -> (String, Value)event = methods.join("|")collect_events
(method, duration) -> Vec<Value>call_and_wait
(call_result, event_params)General
&selfTest plan (6 new tests)
wait_for_any_returns_first_matching_methodwait_for_any_times_out_with_combined_event_stringcollect_events_drains_existing_buffer— server emits 4, assertlen == 4collect_events_returns_empty_on_no_match_without_errorcall_and_wait_resolves_with_event— uses thenotify-then-respond echo handler that exercises the race-prone pathcall_and_wait_propagates_call_errorjust qagreen locally — 46/46 unit testsNotes for the reviewer
Fn(notFnOnce/FnMut) since they may be called many times during a buffer scan or broadcast loop.collect_eventscould be made smarter by listening on the broadcast in a singlerecv_manystyle, but the simple loop is sufficient for the spec and easier to reason about.call_and_waitdeliberately callsself.call(...)directly rather than building the request inline so it inherits the same id-routing, RpcError mapping, and timeout behaviour. Thetimeoutparameter oncall_and_waitis the event wait, not the call wait — the call uses its own default 30 s.notifymethod on the test echo server (added in #5) was the right primitive: emits notification then responds, which is precisely the casecall_and_waitexists to handle.Review — wait_for_any, collect_events, call_and_wait (#7)
call_and_wait— vraiment race-freeL'abonnement avant l'envoi de l'appel garantit qu'une notification déclenchée en réponse à l'appel ne peut pas être manquée même si elle arrive avant la réponse RPC. C'est le cas d'usage typique et c'est géré correctement.
collect_events— drain greedy après chaque broadcastLe drain est greedy après chaque signal broadcast — correct. Les notifications arrivant pendant le drain seront dans le buffer au prochain tour de boucle. Comportement sain.
wait_for_any— timeout event stringLisible dans les messages d'erreur (
Timeout { event: "a|b", ... }). Bon choix.Minor :
drain_first_any— double itérationL'implémentation cherche la position puis appelle
remove(pos). Pour unVecDequec'est O(n) dans les deux cas, donc pas de gain à une implémentation combinée. Correct.Tests
call_and_wait_propagates_call_error— cas important vérifié.collect_events_returns_empty_on_no_match_without_error— vérifie que collect ne panic ni n'erreur.Aucun bloquant.
✅ Pas de bloquant —
call_and_waitvraiment race-free, API des trois helpers claire et bien testée.