Skip to content

fix: setProviderAndWait does not hang on ProviderError #35

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

Merged
merged 1 commit into from
Jan 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion Sources/OpenFeature/OpenFeatureAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension OpenFeatureAPI {
var holder: [AnyCancellable] = []
await withCheckedContinuation { continuation in
let stateObserver = provider.observe().sink {
if $0 == .ready {
if $0 == .ready || $0 == .error {
continuation.resume()
holder.removeAll()
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/OpenFeatureTests/DeveloperExperienceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,24 @@ final class DeveloperExperienceTests: XCTestCase {
let provider = InjectableEventHandlerProvider(eventHandler: eventHandler)
Task {
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider)
wait(for: [readyExpectation], timeout: 0)
wait(for: [readyExpectation], timeout: 1)
initCompleteExpectation.fulfill()
}

wait(for: [staleExpectation], timeout: 1)
eventHandler.send(.ready)
wait(for: [initCompleteExpectation], timeout: 2)
wait(for: [initCompleteExpectation], timeout: 1)

let errorProviderExpectation = XCTestExpectation()
let brokenProvider = AlwaysBrokenProvider()
Task {
await OpenFeatureAPI.shared.setProviderAndWait(provider: brokenProvider)
wait(for: [errorExpectation], timeout: 2)
errorProviderExpectation.fulfill()
}

eventHandler.send(.error)
wait(for: [errorProviderExpectation], timeout: 2)
}
}

Expand Down