Skip to content

Commit

Permalink
fix: setProviderAndWait does not hang on ProviderError (#35)
Browse files Browse the repository at this point in the history
## This PR
`setProviderAndWait` returns if `ProviderError` event has been emitted

### Related Issues
N/A

### How to test
Unit test added

Signed-off-by: Nicky Bondarenko <[email protected]>
  • Loading branch information
nickybondarenko authored Jan 30, 2024
1 parent 3ce6b8d commit 5661080
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit 5661080

Please sign in to comment.