Add deterministic test synchronization and resolve race conditions in async
client initialization.
New Features:
- Add Client.await_init_sent/2 to block until the initialize request is
sent to the transport, enabling reliable test synchronization without
flaky mailbox timing dependencies.
- Implement pre-subscriber buffering for inbound stream events and SDK
messages. Events are now queued until the first subscriber attaches,
preventing silent drops during async startup sequences.
- Add stream_buffer_limit option to Options (default: 1000) controlling
maximum buffered entries before first subscriber. Oldest entries are
dropped when limit is exceeded, with warning logged on flush.
Bug Fixes:
- Resolve intermittent test failures caused by race conditions where
handle_continue initialization completed after short assert_receive
timeouts expired.
- Fix stream events being silently dropped when active_subscriber was
nil by auto-assigning the first subscriber as active and flushing
buffered events immediately.
- Legacy subscribe call now properly sets active_subscriber when nil
and flushes pending inbound buffer to prevent indefinite buffering.
Test Infrastructure:
- Increase init message assertion timeouts from 200ms to 1000ms across
all client tests for reliability under CI load.
- Replace flaky assert_receive patterns with await_init_sent/2 followed
by explicit message consumption for deterministic test behavior.
- Add dedicated client_init_sent_test.exs validating the new readiness
API contract.
- Add pre-subscribe buffering test in client_streaming_test.exs
verifying events and messages are delivered after late subscription.
Internal Changes:
- Add init_waiters list to client state for tracking callers awaiting
initialize send completion.
- Add pending_inbound queue with count and dropped tracking fields.
- Refactor broadcast_message to return updated state for buffer support.
- Extract ensure_active_subscriber/1 and buffer_stream_events/2 helpers.
- Update CLI version references in docs from 2.1.1 to 2.1.7.