From 2cbad3312aefc95f0cf19ad7b2cc30faba727bcd Mon Sep 17 00:00:00 2001 From: Tristan Celder Date: Sun, 19 Apr 2020 09:54:31 +0100 Subject: [PATCH] Standardised ReplaySubject double subscribe behaviour Thanks, @jasdev, for the heads-up! --- Sources/Entwine/Operators/ReplaySubject.swift | 1 - Tests/EntwineTests/ReplaySubjectTests.swift | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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() {