mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-04 02:46:35 -06:00
Fixes #2214. ## Summary Updates to building with Xcode 14 as the minimum. Updates all dependencies (as many both require Xcode 14 to update and would not work with it without updating). ## Any other notes This excludes `arm64` (new in Xcode 14) from watchOS builds. This is due to App Store Connect having a bad heuristic for file size: > ITMS-90389: Size Limit Exceeded - The size of watch application '/Payload/Home Assistant.app/Watch/HomeAssistant-WatchApp.app' (102MB) has exceeded the 75MB size limit. Our binary file is larger than 75 MB unthinned and our thinned install size is sub-25 MB, so I don't think this is testing the right thing. In either case, we're somehow below whatever the limit actually is with just `arm64_32_v8` and `arm_v7k` slices. The first build on TF using the Xcode 14 build for distribution is 2022.413.
121 lines
4.4 KiB
Swift
121 lines
4.4 KiB
Swift
import Foundation
|
|
import PromiseKit
|
|
@testable import Shared
|
|
import XCTest
|
|
|
|
class HomeAssistantBackgroundTaskTests: XCTestCase {
|
|
enum TestError: Error {
|
|
case any
|
|
}
|
|
|
|
func testExpiredDeliversError() {
|
|
let expectedIdentifier = 123_456
|
|
let expectedRemaining: TimeInterval = 456
|
|
|
|
let wrappingExpectation = expectation(description: "wrapping")
|
|
let endExpectation = expectation(description: "endBackgroundTask")
|
|
var expire: (() -> Void)?
|
|
|
|
let promise: Promise<String> = HomeAssistantBackgroundTask.execute(
|
|
withName: "name",
|
|
beginBackgroundTask: { inName, inExpire -> (Int, TimeInterval) in
|
|
XCTAssertEqual(inName, "name")
|
|
expire = inExpire
|
|
return (expectedIdentifier, expectedRemaining)
|
|
}, endBackgroundTask: { (inIdentifier: Int) in
|
|
if inIdentifier == expectedIdentifier {
|
|
endExpectation.fulfill()
|
|
} else {
|
|
XCTFail("should not have called with identifier \(inIdentifier)")
|
|
}
|
|
}, wrapping: { givenRemaining in
|
|
XCTAssertEqual(givenRemaining, expectedRemaining)
|
|
wrappingExpectation.fulfill()
|
|
return .value("hello!")
|
|
}
|
|
)
|
|
|
|
expire?()
|
|
|
|
// it still needs to tell to end the task
|
|
wait(for: [endExpectation, wrappingExpectation], timeout: 10.0)
|
|
|
|
XCTAssertThrowsError(try hang(promise)) { error in
|
|
XCTAssertEqual(error as? BackgroundTaskError, BackgroundTaskError.outOfTime)
|
|
}
|
|
}
|
|
|
|
func testRejectedDeliversError() {
|
|
let (underlyingPromise, underlyingSeal) = Promise<String>.pending()
|
|
|
|
let endExpectedIdentifier = 123_456
|
|
let expectedRemaining: TimeInterval = 456
|
|
|
|
let wrappingExpectation = expectation(description: "wrapping")
|
|
|
|
let endExpectation = expectation(description: "endBackgroundTask")
|
|
|
|
let promise: Promise<String> = HomeAssistantBackgroundTask.execute(
|
|
withName: "name",
|
|
beginBackgroundTask: { inName, _ -> (Int, TimeInterval) in
|
|
XCTAssertEqual(inName, "name")
|
|
return (endExpectedIdentifier, expectedRemaining)
|
|
}, endBackgroundTask: { (inIdentifier: Int) in
|
|
if inIdentifier == endExpectedIdentifier {
|
|
endExpectation.fulfill()
|
|
} else {
|
|
XCTFail("should not have called with identifier \(inIdentifier)")
|
|
}
|
|
}, wrapping: { givenRemaining in
|
|
XCTAssertEqual(givenRemaining, expectedRemaining)
|
|
wrappingExpectation.fulfill()
|
|
return underlyingPromise
|
|
}
|
|
)
|
|
|
|
underlyingSeal.reject(TestError.any)
|
|
|
|
// it still needs to tell to end the task
|
|
wait(for: [endExpectation, wrappingExpectation], timeout: 10.0)
|
|
|
|
XCTAssertThrowsError(try hang(promise)) { error in
|
|
XCTAssertEqual(error as? TestError, TestError.any)
|
|
}
|
|
}
|
|
|
|
func testFulfilledDeliversValue() throws {
|
|
let (underlyingPromise, underlyingSeal) = Promise<String>.pending()
|
|
|
|
let expectedIdentifier = 123_456
|
|
let expectedRemaining: TimeInterval = 456
|
|
|
|
let wrappingExpectation = expectation(description: "wrapping")
|
|
let endExpectation = expectation(description: "endBackgroundTask")
|
|
|
|
let promise: Promise<String> = HomeAssistantBackgroundTask.execute(
|
|
withName: "name",
|
|
beginBackgroundTask: { inName, _ -> (Int, TimeInterval) in
|
|
XCTAssertEqual(inName, "name")
|
|
return (expectedIdentifier, expectedRemaining)
|
|
}, endBackgroundTask: { (inIdentifier: Int) in
|
|
if inIdentifier == expectedIdentifier {
|
|
endExpectation.fulfill()
|
|
} else {
|
|
XCTFail("should not have called with identifier \(inIdentifier)")
|
|
}
|
|
}, wrapping: { givenRemaining in
|
|
XCTAssertEqual(givenRemaining, expectedRemaining)
|
|
wrappingExpectation.fulfill()
|
|
return underlyingPromise
|
|
}
|
|
)
|
|
|
|
underlyingSeal.fulfill("dogs")
|
|
|
|
// it still needs to tell to end the task
|
|
wait(for: [endExpectation, wrappingExpectation], timeout: 10.0)
|
|
|
|
XCTAssertEqual(try hang(promise), "dogs")
|
|
}
|
|
}
|