diff --git a/Sources/Entwine/Operators/ReplaySubject.swift b/Sources/Entwine/Operators/ReplaySubject.swift index d0f5095..fb90c9d 100644 --- a/Sources/Entwine/Operators/ReplaySubject.swift +++ b/Sources/Entwine/Operators/ReplaySubject.swift @@ -58,7 +58,6 @@ extension ReplaySubject: Publisher { guard !subscriberIdentifiers.contains(subscriber.combineIdentifier) else { subscriber.receive(subscription: Subscriptions.empty) - subscriber.receive(completion: .finished) return } diff --git a/Tests/EntwineTests/ReplaySubjectTests.swift b/Tests/EntwineTests/ReplaySubjectTests.swift index a5eaadc..33b44dc 100644 --- a/Tests/EntwineTests/ReplaySubjectTests.swift +++ b/Tests/EntwineTests/ReplaySubjectTests.swift @@ -451,6 +451,28 @@ final class ReplaySubjectTests: XCTestCase { XCTAssertEqual(results2.recordedOutput, results1.recordedOutput) } + + func testDuplicateSubscriptionMatchesControl() { + + var subject: ReplaySubject! = nil + var control: PassthroughSubject! = nil + + let results1 = scheduler.createTestableSubscriber(Int.self, Never.self) + let results2 = scheduler.createTestableSubscriber(Int.self, Never.self) + + scheduler.schedule(after: 100) { subject = ReplaySubject(maxBufferSize: 1) } + scheduler.schedule(after: 100) { control = PassthroughSubject() } + scheduler.schedule(after: 200) { subject.subscribe(results1) } + scheduler.schedule(after: 200) { control.subscribe(results2) } + scheduler.schedule(after: 300) { subject.subscribe(results1) } + scheduler.schedule(after: 300) { control.subscribe(results2) } + scheduler.schedule(after: 400) { subject = nil } + scheduler.schedule(after: 400) { control = nil } + + scheduler.resume() + + XCTAssertEqual(results2.recordedOutput, results1.recordedOutput) + } func testSendSubscriptionInitialDemandUnlimitedBehaviorMatchesControl() {