Fix foreground error assignment and test persistence recovery

This commit is contained in:
2026-09-12 21:42:41 +03:00
parent c461c26f7f
commit bde6f7a466
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ final class PlayerStore: ObservableObject {
// Retry loading if Keychain was locked when the app was created. // Retry loading if Keychain was locked when the app was created.
if connection == nil { if connection == nil {
do { connection = try storage.load() } do { connection = try storage.load() }
catch { error = BridgeError.describe(error) } catch { self.error = BridgeError.describe(error) }
} }
if discoveryEnabled { discovery.start() } if discoveryEnabled { discovery.start() }
resume() resume()
+17
View File
@@ -49,6 +49,23 @@ final class ResilienceTests: XCTestCase {
XCTAssertFalse(store.connected) XCTAssertFalse(store.connected)
} }
func testRetriesStorageLoadWhenForegroundBecomesAvailable() async throws {
let saved = try connection("storage-unlock")
var loads = 0
let storage = ConnectionStorage(load: {
loads += 1
if loads == 1 { throw BridgeError.message("Keychain locked") }
return saved
}, save: { _ in }, delete: {})
let store = PlayerStore(storage: storage, discoveryEnabled: false)
defer { store.setActive(false) }
XCTAssertNil(store.connection)
store.setActive(true)
try await eventually { store.connected }
XCTAssertEqual(loads, 2)
XCTAssertNil(store.error)
}
func testArtworkRetriesAfter404WithoutTrackChange() async throws { func testArtworkRetriesAfter404WithoutTrackChange() async throws {
let store = try store("artwork") let store = try store("artwork")
defer { store.setActive(false) } defer { store.setActive(false) }