Test that one subscriber leaving keeps the multicast upstream for the other - #73
Conversation
|
These are useful scenarios to cover: when one subscriber leaves, the other should keep receiving values. Covering both
Validation was on macOS with Swift 6.4, applying this PR's test file to current |
… other Two subscribers share a hand-fed upstream; the one holding the pull is cancelled, or releases its iterator, while the other must still receive every element and finish normally. Covers connect() and autoconnect(). A's iterator is created inside its task, so no copy outlives it. The test waits for A to finish while upstream is still silent, checks that the subject has dropped A's registration, and only then sends elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T8cahEd4GfsHQ89sNrmP4p
697dc49 to
fbc8f2f
Compare
Four tests for
AsyncMulticastSequencewith two subscribers: subscriber A leaves, by task cancellation or by releasing its iterator, underconnect()and underautoconnect(), and subscriber B must keep receiving the shared upstream's elements and finish with it.They exercise the case noted when closing #38 ("cancelling one subscriber terminates the shared upstream for another subscriber"), which fd6753e fixed by pulling the upstream on a task of its own. A hand-fed
AsyncThrowingStreamwith an expectation on enteringnext()makes A the puller deterministically before B starts; no sleeps.A's iterator is created inside its task, so no copy of it outlives A. The test waits for A to finish while upstream is still silent, checks that the subject (read through
@testable import) has dropped A's registration, and only then sends elements; A's own result is asserted too.On Linux (Swift 6.4, x86_64), rebased on b4adff5: the multicast suites pass (11 tests), 20 runs in a row. With the multicast implementation from before fd6753e the two cancellation tests fail; with a retained copy of A's iterator the two release tests fail on the registration check.
🤖 Generated with Claude Code
https://claude.ai/code/session_01T8cahEd4GfsHQ89sNrmP4p