-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Rollouts] RC interop implementation #12173
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3bd59f0
[Rollouts] RC interop implementation
themiswang b1f2e4b
fix pod dependency
themiswang 8ef8ddf
remove failed unit tests assertion
themiswang 9d9b101
fix watchOS example podfile
themiswang 9eb3d54
really try to fix the unit tests
themiswang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRemoteConfigInterop) | ||
public protocol RemoteConfigInterop { | ||
func registerRolloutsStateSubscriber(_ subscriber: RolloutsStateSubscriber, | ||
for namespace: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRolloutAssignment) | ||
public class RolloutAssignment: NSObject { | ||
@objc public var rolloutId: String | ||
@objc public var variantId: String | ||
@objc public var templateVersion: Int64 | ||
@objc public var parameterKey: String | ||
@objc public var parameterValue: String | ||
|
||
public init(rolloutId: String, variantId: String, templateVersion: Int64, parameterKey: String, | ||
parameterValue: String) { | ||
self.rolloutId = rolloutId | ||
self.variantId = variantId | ||
self.templateVersion = templateVersion | ||
self.parameterKey = parameterKey | ||
self.parameterValue = parameterValue | ||
super.init() | ||
} | ||
} | ||
|
||
@objc(FIRRolloutsState) | ||
public class RolloutsState: NSObject { | ||
@objc public var assignments: Set<RolloutAssignment> = Set() | ||
|
||
public init(assignmentList: [RolloutAssignment]) { | ||
for assignment in assignmentList { | ||
assignments.insert(assignment) | ||
} | ||
super.init() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
FirebaseRemoteConfig/Interop/RolloutsStateSubscriber.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
|
||
@objc(FIRRolloutsStateSubscriber) | ||
public protocol RolloutsStateSubscriber { | ||
func rolloutsStateDidChange(_ rolloutsState: RolloutsState) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
FirebaseRemoteConfig/Tests/SwiftUnit/RemoteConfigInteropTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import FirebaseRemoteConfigInterop | ||
import XCTest | ||
|
||
class MockRCInterop: RemoteConfigInterop { | ||
weak var subscriber: FirebaseRemoteConfigInterop.RolloutsStateSubscriber? | ||
func registerRolloutsStateSubscriber(_ subscriber: FirebaseRemoteConfigInterop | ||
.RolloutsStateSubscriber, | ||
for namespace: String) { | ||
self.subscriber = subscriber | ||
} | ||
} | ||
|
||
class MockRolloutSubscriber: RolloutsStateSubscriber { | ||
var isSubscriberCalled = false | ||
var rolloutsState: RolloutsState? | ||
func rolloutsStateDidChange(_ rolloutsState: FirebaseRemoteConfigInterop.RolloutsState) { | ||
isSubscriberCalled = true | ||
self.rolloutsState = rolloutsState | ||
} | ||
} | ||
|
||
final class RemoteConfigInteropTests: XCTestCase { | ||
let rollouts: RolloutsState = { | ||
let assignment1 = RolloutAssignment( | ||
rolloutId: "rollout_1", | ||
variantId: "control", | ||
templateVersion: 1, | ||
parameterKey: "my_feature", | ||
parameterValue: "false" | ||
) | ||
let assignment2 = RolloutAssignment( | ||
rolloutId: "rollout_2", | ||
variantId: "enabled", | ||
templateVersion: 123, | ||
parameterKey: "themis_big_feature", | ||
parameterValue: "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" | ||
) | ||
let rollouts = RolloutsState(assignmentList: [assignment1, assignment2]) | ||
return rollouts | ||
}() | ||
|
||
func testRemoteConfigIntegration() throws { | ||
let rcSubscriber = MockRolloutSubscriber() | ||
let rcInterop = MockRCInterop() | ||
rcInterop.registerRolloutsStateSubscriber(rcSubscriber, for: "namespace") | ||
rcInterop.subscriber?.rolloutsStateDidChange(rollouts) | ||
|
||
XCTAssertTrue(rcSubscriber.isSubscriberCalled) | ||
XCTAssertEqual(rcSubscriber.rolloutsState?.assignments.count, 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#import "FirebaseRemoteConfig/Sources/FIRRemoteConfigComponent.h" | ||
#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h" | ||
#import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h" | ||
@import FirebaseRemoteConfigInterop; | ||
|
||
@interface FIRRemoteConfigComponentTest : XCTestCase | ||
@end | ||
|
@@ -31,6 +32,7 @@ - (void)tearDown { | |
|
||
// Clear out any apps that were called with `configure`. | ||
[FIRApp resetApps]; | ||
[FIRRemoteConfigComponent clearAllComponentInstances]; | ||
} | ||
|
||
- (void)testRCInstanceCreationAndCaching { | ||
|
@@ -92,7 +94,8 @@ - (void)testInitialization { | |
} | ||
|
||
- (void)testRegistersAsLibrary { | ||
XCTAssertEqual([FIRRemoteConfigComponent componentsToRegister].count, 1); | ||
// Now component has two register, one is provider and another one is Interop | ||
XCTAssertEqual([FIRRemoteConfigComponent componentsToRegister].count, 2); | ||
|
||
// Configure a test FIRApp for fetching an instance of the FIRRemoteConfigProvider. | ||
NSString *appName = [self generatedTestAppName]; | ||
|
@@ -101,12 +104,50 @@ - (void)testRegistersAsLibrary { | |
|
||
// Attempt to fetch the component and verify it's a valid instance. | ||
id<FIRRemoteConfigProvider> provider = FIR_COMPONENT(FIRRemoteConfigProvider, app.container); | ||
id<FIRRemoteConfigInterop> interop = FIR_COMPONENT(FIRRemoteConfigInterop, app.container); | ||
XCTAssertNotNil(provider); | ||
XCTAssertNotNil(interop); | ||
|
||
// Ensure that the instance that comes from the container is cached. | ||
id<FIRRemoteConfigProvider> sameProvider = FIR_COMPONENT(FIRRemoteConfigProvider, app.container); | ||
id<FIRRemoteConfigInterop> sameInterop = FIR_COMPONENT(FIRRemoteConfigInterop, app.container); | ||
XCTAssertNotNil(sameProvider); | ||
XCTAssertNotNil(sameInterop); | ||
XCTAssertEqual(provider, sameProvider); | ||
XCTAssertEqual(interop, sameInterop); | ||
|
||
// Dynamic typing, both prototols are refering to the same component instance | ||
id providerID = provider; | ||
id interopID = interop; | ||
XCTAssertEqualObjects(providerID, interopID); | ||
} | ||
|
||
- (void)testTwoAppsCreateTwoComponents { | ||
NSString *appName = [self generatedTestAppName]; | ||
[FIRApp configureWithName:appName options:[self fakeOptions]]; | ||
FIRApp *app = [FIRApp appNamed:appName]; | ||
|
||
[FIRApp configureWithOptions:[self fakeOptions]]; | ||
FIRApp *defaultApp = [FIRApp defaultApp]; | ||
XCTAssertNotNil(defaultApp); | ||
XCTAssertNotEqualObjects(app, defaultApp); | ||
|
||
id<FIRRemoteConfigProvider> provider = FIR_COMPONENT(FIRRemoteConfigProvider, app.container); | ||
id<FIRRemoteConfigInterop> interop = FIR_COMPONENT(FIRRemoteConfigInterop, app.container); | ||
id<FIRRemoteConfigProvider> defaultAppProvider = | ||
FIR_COMPONENT(FIRRemoteConfigProvider, defaultApp.container); | ||
id<FIRRemoteConfigInterop> defaultAppInterop = | ||
FIR_COMPONENT(FIRRemoteConfigInterop, defaultApp.container); | ||
|
||
id providerID = provider; | ||
id interopID = interop; | ||
id defaultAppProviderID = defaultAppProvider; | ||
id defaultAppInteropID = defaultAppInterop; | ||
|
||
XCTAssertEqualObjects(providerID, interopID); | ||
XCTAssertEqualObjects(defaultAppProviderID, defaultAppInteropID); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thinking: this asserts the singleton logic works 👍 |
||
// Check two apps get their own component to register | ||
XCTAssertNotEqualObjects(interopID, defaultAppInteropID); | ||
} | ||
|
||
- (void)testThrowsWithEmptyGoogleAppID { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the other interops are protocols only. Why is there code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This object will be shared between Crashlytics and RC to transfer the Rollout related data. We are following the similar implementation on Android side. cc @danasilver if you want to add more input on this!