Skip to content

Commit

Permalink
Standardised ReplaySubject double subscribe behaviour
Browse files Browse the repository at this point in the history
Thanks, @jasdev, for the heads-up!
  • Loading branch information
tcldr committed Apr 19, 2020
1 parent b839c9f commit 2cbad33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion Sources/Entwine/Operators/ReplaySubject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ extension ReplaySubject: Publisher {

guard !subscriberIdentifiers.contains(subscriber.combineIdentifier) else {
subscriber.receive(subscription: Subscriptions.empty)
subscriber.receive(completion: .finished)
return
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/EntwineTests/ReplaySubjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,28 @@ final class ReplaySubjectTests: XCTestCase {

XCTAssertEqual(results2.recordedOutput, results1.recordedOutput)
}

func testDuplicateSubscriptionMatchesControl() {

var subject: ReplaySubject<Int, Never>! = nil
var control: PassthroughSubject<Int, Never>! = 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() {

Expand Down

0 comments on commit 2cbad33

Please sign in to comment.