Skip to content

Commit a67da04

Browse files
authored
Only update experiments for firebase namespace (#7604)
* Only update experiments for firebase namespace * Update tests * Add changelog
1 parent 64d50a7 commit a67da04

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [fixed] Store fetch metadata per namespace to address activation issues. (#7179)
3+
- [fixed] Only update experiment data for `firebase` namespace fetch requests to ensure correct experiment exposures. (#7604)
34

45
# v7.7.0
56
- [added] Added community support for watchOS. (#7481)

FirebaseRemoteConfig/Sources/RCNConfigFetch.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,13 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
480480
// Update config content to cache and DB.
481481
[strongSelf->_content updateConfigContentWithResponse:fetchedConfig
482482
forNamespace:strongSelf->_FIRNamespace];
483-
// Update experiments.
484-
[strongSelf->_experiment
485-
updateExperimentsWithResponse:fetchedConfig[RCNFetchResponseKeyExperimentDescriptions]];
483+
// Update experiments only for 3p namespace
484+
NSString *namespace = [strongSelf->_FIRNamespace
485+
substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
486+
if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
487+
[strongSelf->_experiment updateExperimentsWithResponse:
488+
fetchedConfig[RCNFetchResponseKeyExperimentDescriptions]];
489+
}
486490
} else {
487491
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000063",
488492
@"Empty response with no fetched config.");

FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ + (NSUserDefaults *)sharedUserDefaultsForBundleIdentifier:(NSString *)bundleIden
8181

8282
typedef NS_ENUM(NSInteger, RCNTestRCInstance) {
8383
RCNTestRCInstanceDefault,
84-
RCNTestRCNumTotalInstances, // TODO(mandard): Remove once OCMock issue is resolved (#4877).
8584
RCNTestRCInstanceSecondNamespace,
8685
RCNTestRCInstanceSecondApp,
86+
RCNTestRCNumTotalInstances
8787
};
8888

8989
@interface RCNRemoteConfigTest : XCTestCase {
@@ -463,6 +463,54 @@ - (void)testEnumeratingConfigResults {
463463
}];
464464
}
465465

466+
- (void)testFetch3pNamespaceUpdatesExperiments {
467+
[[_experimentMock expect] updateExperimentsWithResponse:[OCMArg any]];
468+
469+
XCTestExpectation *expectation = [self
470+
expectationWithDescription:
471+
[NSString
472+
stringWithFormat:@"Fetch call for 'firebase' namespace updates experiment data"]];
473+
XCTAssertEqual(_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
474+
FIRRemoteConfigFetchStatusNoFetchYet);
475+
FIRRemoteConfigFetchCompletion fetchCompletion =
476+
^void(FIRRemoteConfigFetchStatus status, NSError *error) {
477+
XCTAssertEqual(self->_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
478+
FIRRemoteConfigFetchStatusSuccess);
479+
XCTAssertNil(error);
480+
[expectation fulfill];
481+
};
482+
[_configInstances[RCNTestRCInstanceDefault] fetchWithExpirationDuration:43200
483+
completionHandler:fetchCompletion];
484+
[self waitForExpectationsWithTimeout:_expectationTimeout
485+
handler:^(NSError *error) {
486+
XCTAssertNil(error);
487+
}];
488+
}
489+
490+
- (void)testFetchOtherNamespaceDoesntUpdateExperiments {
491+
[[_experimentMock reject] updateExperimentsWithResponse:[OCMArg any]];
492+
493+
XCTestExpectation *expectation =
494+
[self expectationWithDescription:
495+
[NSString stringWithFormat:@"Fetch call for namespace other than 'firebase' "
496+
@"doesn't update experiment data"]];
497+
XCTAssertEqual(_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
498+
FIRRemoteConfigFetchStatusNoFetchYet);
499+
FIRRemoteConfigFetchCompletion fetchCompletion =
500+
^void(FIRRemoteConfigFetchStatus status, NSError *error) {
501+
XCTAssertEqual(self->_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
502+
FIRRemoteConfigFetchStatusSuccess);
503+
XCTAssertNil(error);
504+
[expectation fulfill];
505+
};
506+
[_configInstances[RCNTestRCInstanceSecondNamespace] fetchWithExpirationDuration:43200
507+
completionHandler:fetchCompletion];
508+
[self waitForExpectationsWithTimeout:_expectationTimeout
509+
handler:^(NSError *error) {
510+
XCTAssertNil(error);
511+
}];
512+
}
513+
466514
- (void)testFetchConfigsFailed {
467515
// Override the setup values to return back an error status.
468516
RCNConfigContent *configContent = [[RCNConfigContent alloc] initWithDBManager:_DBManager];
@@ -1323,10 +1371,12 @@ - (FIROptions *)firstAppOptions {
13231371
}
13241372

13251373
- (FIROptions *)secondAppOptions {
1326-
FIROptions *options =
1327-
[[FIROptions alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]]
1328-
pathForResource:@"SecondApp-GoogleService-Info"
1329-
ofType:@"plist"]];
1374+
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
1375+
#if SWIFT_PACKAGE
1376+
bundle = Firebase_RemoteConfigUnit_SWIFTPM_MODULE_BUNDLE();
1377+
#endif
1378+
NSString *plistPath = [bundle pathForResource:@"SecondApp-GoogleService-Info" ofType:@"plist"];
1379+
FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:plistPath];
13301380
XCTAssertNotNil(options);
13311381
return options;
13321382
}

0 commit comments

Comments
 (0)