Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update testSuccessfulRetry and code to make it pass. #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Sources/Operators/RetryWhen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension Publishers.RetryWhen {
class Subscription<Downstream>: Combine.Subscription where Downstream: Subscriber, Downstream.Input == Upstream.Output, Downstream.Failure == Upstream.Failure {
private let upstream: Upstream
private let downstream: Downstream
private let errorSubject = PassthroughSubject<Upstream.Failure, Never>()
private let errorSubject = CurrentValueSubject<Upstream.Failure?, Never>(nil)
private var sink: Sink<Upstream, Downstream>?
private var cancellable: AnyCancellable?

Expand All @@ -64,7 +64,7 @@ extension Publishers.RetryWhen {
return nil
}
)
self.cancellable = errorTrigger(errorSubject.eraseToAnyPublisher())
self.cancellable = errorTrigger(errorSubject.compactMap { $0 }.eraseToAnyPublisher())
.sink(
receiveCompletion: { [sink] completion in
switch completion {
Expand All @@ -81,7 +81,6 @@ extension Publishers.RetryWhen {
upstream.subscribe(sink)
}
)
upstream.subscribe(sink!)
}

func request(_ demand: Subscribers.Demand) {
Expand Down
7 changes: 5 additions & 2 deletions Tests/RetryWhenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RetryWhenTests: XCTestCase {

func testSuccessfulRetry() {
var times = 0

var retriesCount = 0
var expectedOutput: Int?

var completion: Subscribers.Completion<RetryWhenTests.MyError>?
Expand All @@ -57,7 +57,9 @@ class RetryWhenTests: XCTestCase {
}
})
.retryWhen { error in
error.map { _ in }
error
.handleEvents(receiveOutput: { _ in retriesCount += 1})
.map { _ in }
}
.sink(
receiveCompletion: { completion = $0 },
Expand All @@ -70,6 +72,7 @@ class RetryWhenTests: XCTestCase {
)
XCTAssertEqual(completion, .finished)
XCTAssertEqual(times, 2)
XCTAssertEqual(retriesCount, 1)
}

func testRetryFailure() {
Expand Down