Skip to content

Commit 3b0235a

Browse files
committed
Add Swift test and fixes
1 parent f9c6adc commit 3b0235a

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

FirebaseFunctions/Sources/HTTPSCallable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ open class HTTPSCallable: NSObject {
7979
completion: @escaping (HTTPSCallableResult?,
8080
Error?) -> Void) {
8181
if #available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *) {
82-
Task {
82+
Task { @MainActor in
8383
do {
8484
let result = try await call(data)
8585
completion(result, nil)

FirebaseFunctions/Tests/Integration/IntegrationTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,38 @@ class IntegrationTests: XCTestCase {
867867
XCTAssertEqual(response, expected)
868868
}
869869
}
870+
871+
func testFunctionsReturnsOnMainThread() {
872+
let expectation = expectation(description: #function)
873+
functions.httpsCallable(
874+
"scalarTest",
875+
requestAs: Int16.self,
876+
responseAs: Int.self
877+
).call(17) { result in
878+
guard case .success = result else {
879+
return XCTFail("Unexpected failure.")
880+
}
881+
XCTAssert(Thread.isMainThread)
882+
expectation.fulfill()
883+
}
884+
waitForExpectations(timeout: 5)
885+
}
886+
887+
func testFunctionsThrowsOnMainThread() {
888+
let expectation = expectation(description: #function)
889+
functions.httpsCallable(
890+
"httpErrorTest",
891+
requestAs: [Int].self,
892+
responseAs: Int.self
893+
).call([]) { result in
894+
guard case .failure = result else {
895+
return XCTFail("Unexpected failure.")
896+
}
897+
XCTAssert(Thread.isMainThread)
898+
expectation.fulfill()
899+
}
900+
waitForExpectations(timeout: 5)
901+
}
870902
}
871903

872904
// MARK: - Streaming

FirebaseFunctions/Tests/Unit/FunctionsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class FunctionsTests: XCTestCase {
290290
}
291291

292292
XCTAssertEqual(error as NSError, networkError)
293-
293+
XCTAssert(Thread.isMainThread)
294294
completionExpectation.fulfill()
295295
}
296296

0 commit comments

Comments
 (0)