Skip to content

Commit a7e7eb1

Browse files
authored
[Infra] Merge branch 'release-11.4' into 'main' (#13958)
1 parent 7a10b3b commit a7e7eb1

File tree

8 files changed

+88
-64
lines changed

8 files changed

+88
-64
lines changed

FirebaseAuth/Tests/Unit/AuthBackendRPCImplementationTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ class AuthBackendRPCImplementationTests: RPCBaseTests {
534534

535535
#if COCOAPODS || SWIFT_PACKAGE
536536
private class FakeHeartbeatLogger: NSObject, FIRHeartbeatLoggerProtocol {
537+
func headerValue() -> String? {
538+
// `asyncHeaderValue` should be used instead.
539+
fatalError("FakeHeartbeatLogger headerValue should not be used in tests.")
540+
}
541+
537542
func asyncHeaderValue() async -> String? {
538543
let payload = flushHeartbeatsIntoPayload()
539544
guard !payload.isEmpty else {

FirebaseCore/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Firebase 11.4.2
2+
- [fixed] CocoaPods only release to fix iOS 12 build failure resulting from
3+
incomplete implementation in the FirebaseCoreInternal CocoaPod.
4+
5+
# Firebase 11.4.1
6+
- [fixed] CocoaPods only release to revert breaking change in
7+
`FirebaseCoreExtension` SDK. (#13942)
8+
19
# Firebase 11.4.0
210
- [fixed] Fixed issue building documentation with some Firebase products. (#13756)
311

FirebaseCore/Extension/FIRHeartbeatLogger.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ typedef NS_ENUM(NSInteger, FIRDailyHeartbeatCode) {
4444
API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
4545

4646
/// Return the header value for the heartbeat logger.
47-
- (NSString *_Nullable)
48-
headerValue NS_SWIFT_UNAVAILABLE("Use `asyncHeaderValue() async -> String?` instead.");
47+
- (NSString *_Nullable)headerValue;
4948
#endif // FIREBASE_BUILD_CMAKE
5049

5150
@end

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatController.swift

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,30 @@ public final class HeartbeatController {
126126
}
127127
}
128128

129-
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
130-
public func flushAsync() async -> HeartbeatsPayload {
131-
return await withCheckedContinuation { continuation in
132-
let resetTransform = { (heartbeatsBundle: HeartbeatsBundle?) -> HeartbeatsBundle? in
133-
guard let oldHeartbeatsBundle = heartbeatsBundle else {
134-
return nil // Storage was empty.
135-
}
136-
// The new value that's stored will use the old's cache to prevent the
137-
// logging of duplicates after flushing.
138-
return HeartbeatsBundle(
139-
capacity: self.heartbeatsStorageCapacity,
140-
cache: oldHeartbeatsBundle.lastAddedHeartbeatDates
141-
)
129+
public func flushAsync(completionHandler: @escaping (HeartbeatsPayload) -> Void) {
130+
let resetTransform = { (heartbeatsBundle: HeartbeatsBundle?) -> HeartbeatsBundle? in
131+
guard let oldHeartbeatsBundle = heartbeatsBundle else {
132+
return nil // Storage was empty.
142133
}
134+
// The new value that's stored will use the old's cache to prevent the
135+
// logging of duplicates after flushing.
136+
return HeartbeatsBundle(
137+
capacity: self.heartbeatsStorageCapacity,
138+
cache: oldHeartbeatsBundle.lastAddedHeartbeatDates
139+
)
140+
}
143141

144-
// Asynchronously gets and returns the stored heartbeats, resetting storage
145-
// using the given transform.
146-
storage.getAndSetAsync(using: resetTransform) { result in
147-
switch result {
148-
case let .success(heartbeatsBundle):
149-
// If no heartbeats bundle was stored, return an empty payload.
150-
continuation
151-
.resume(returning: heartbeatsBundle?.makeHeartbeatsPayload() ?? HeartbeatsPayload
152-
.emptyPayload)
153-
case .failure:
154-
// If the operation throws, assume no heartbeat(s) were retrieved or set.
155-
continuation.resume(returning: HeartbeatsPayload.emptyPayload)
156-
}
142+
// Asynchronously gets and returns the stored heartbeats, resetting storage
143+
// using the given transform.
144+
storage.getAndSetAsync(using: resetTransform) { result in
145+
switch result {
146+
case let .success(heartbeatsBundle):
147+
// If no heartbeats bundle was stored, return an empty payload.
148+
completionHandler(heartbeatsBundle?.makeHeartbeatsPayload() ?? HeartbeatsPayload
149+
.emptyPayload)
150+
case .failure:
151+
// If the operation throws, assume no heartbeat(s) were retrieved or set.
152+
completionHandler(HeartbeatsPayload.emptyPayload)
157153
}
158154
}
159155
}

FirebaseCore/Internal/Sources/HeartbeatLogging/_ObjC_HeartbeatController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public class _ObjC_HeartbeatController: NSObject {
4949
///
5050
/// - Note: This API is thread-safe.
5151
/// - Returns: A heartbeats payload for the flushed heartbeat(s).
52-
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
53-
public func flushAsync() async -> _ObjC_HeartbeatsPayload {
54-
let heartbeatsPayload = await heartbeatController.flushAsync()
55-
return _ObjC_HeartbeatsPayload(heartbeatsPayload)
52+
public func flushAsync(completionHandler: @escaping (_ObjC_HeartbeatsPayload) -> Void) {
53+
// TODO: When minimum version moves to iOS 13.0, restore the async version
54+
// removed in #13952.
55+
heartbeatController.flushAsync { heartbeatsPayload in
56+
completionHandler(_ObjC_HeartbeatsPayload(heartbeatsPayload))
57+
}
5658
}
5759

5860
/// Synchronously flushes the heartbeat for today.

FirebaseCore/Internal/Tests/Integration/HeartbeatLoggingIntegrationTests.swift

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,36 @@ class HeartbeatLoggingIntegrationTests: XCTestCase {
5252
)
5353
}
5454

55-
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
56-
func testLogAndFlushAsync() async throws {
55+
func testLogAndFlushAsync() throws {
5756
// Given
5857
let heartbeatController = HeartbeatController(id: #function)
5958
let expectedDate = HeartbeatsPayload.dateFormatter.string(from: Date())
59+
let expectation = self.expectation(description: #function)
6060
// When
6161
heartbeatController.log("dummy_agent")
62-
let payload = await heartbeatController.flushAsync()
63-
// Then
64-
try HeartbeatLoggingTestUtils.assertEqualPayloadStrings(
65-
payload.headerValue(),
66-
"""
67-
{
68-
"version": 2,
69-
"heartbeats": [
62+
heartbeatController.flushAsync { payload in
63+
// Then
64+
do {
65+
try HeartbeatLoggingTestUtils.assertEqualPayloadStrings(
66+
payload.headerValue(),
67+
"""
7068
{
71-
"agent": "dummy_agent",
72-
"dates": ["\(expectedDate)"]
69+
"version": 2,
70+
"heartbeats": [
71+
{
72+
"agent": "dummy_agent",
73+
"dates": ["\(expectedDate)"]
74+
}
75+
]
7376
}
74-
]
77+
"""
78+
)
79+
expectation.fulfill()
80+
} catch {
81+
XCTFail("Unexpected error: \(error)")
7582
}
76-
"""
77-
)
83+
}
84+
waitForExpectations(timeout: 1.0)
7885
}
7986

8087
/// This test may flake if it is executed during the transition from one day to the next.

FirebaseCore/Internal/Tests/Unit/HeartbeatControllerTests.swift

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,41 @@ class HeartbeatControllerTests: XCTestCase {
5858
assertHeartbeatControllerFlushesEmptyPayload(controller)
5959
}
6060

61-
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
62-
func testLogAndFlushAsync() async throws {
61+
func testLogAndFlushAsync() throws {
6362
// Given
6463
let controller = HeartbeatController(
6564
storage: HeartbeatStorageFake(),
6665
dateProvider: { self.date }
6766
)
67+
let expectation = expectation(description: #function)
6868

6969
assertHeartbeatControllerFlushesEmptyPayload(controller)
7070

7171
// When
7272
controller.log("dummy_agent")
73-
let heartbeatPayload = await controller.flushAsync()
74-
75-
// Then
76-
try HeartbeatLoggingTestUtils.assertEqualPayloadStrings(
77-
heartbeatPayload.headerValue(),
78-
"""
79-
{
80-
"version": 2,
81-
"heartbeats": [
73+
controller.flushAsync { heartbeatPayload in
74+
// Then
75+
do {
76+
try HeartbeatLoggingTestUtils.assertEqualPayloadStrings(
77+
heartbeatPayload.headerValue(),
78+
"""
8279
{
83-
"agent": "dummy_agent",
84-
"dates": ["2021-11-01"]
80+
"version": 2,
81+
"heartbeats": [
82+
{
83+
"agent": "dummy_agent",
84+
"dates": ["2021-11-01"]
85+
}
86+
]
8587
}
86-
]
88+
"""
89+
)
90+
expectation.fulfill()
91+
} catch {
92+
XCTFail("Unexpected error: \(error)")
8793
}
88-
"""
89-
)
94+
}
95+
waitForExpectations(timeout: 1.0)
9096

9197
assertHeartbeatControllerFlushesEmptyPayload(controller)
9298
}

FirebaseCore/Sources/FIRHeartbeatLogger.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload {
8787
}
8888

8989
- (void)flushHeartbeatsIntoPayloadWithCompletionHandler:
90-
(void (^)(FIRHeartbeatsPayload *))completionHandler {
90+
(void (^)(FIRHeartbeatsPayload *))completionHandler
91+
API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0)) {
9192
[_heartbeatController flushAsyncWithCompletionHandler:^(FIRHeartbeatsPayload *payload) {
9293
completionHandler(payload);
9394
}];

0 commit comments

Comments
 (0)