Skip to content

Commit ec24d6e

Browse files
authored
Merge 990b6d1 into e2542c7
2 parents e2542c7 + 990b6d1 commit ec24d6e

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 9.3.0
22
- [changed] Arrays and Dictionaries are now supported when initializing defaults from a
33
plist. (#8306)
4+
- [fixed] Activate calls will only update experiment data for `firebase` namespace to ensure correct experiment exposures. (#9972)
45

56
# 9.0.0
67
- [changed] The `remoteConfig()` singleton now throws an exception when called before

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,25 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
316316
strongSelf->_settings.lastApplyTimeInterval = [[NSDate date] timeIntervalSince1970];
317317
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000069", @"Config activated.");
318318
[strongSelf->_configContent activatePersonalization];
319-
[strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
319+
320+
// Update experiments only for 3p namespace
321+
NSString *namespace = [strongSelf->_FIRNamespace
322+
substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
323+
if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
324+
[strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
325+
if (completion) {
326+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
327+
completion(YES, nil);
328+
});
329+
}
330+
}];
331+
} else {
320332
if (completion) {
321333
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
322334
completion(YES, nil);
323335
});
324336
}
325-
}];
337+
}
326338
};
327339
dispatch_async(_queue, applyBlock);
328340
}

FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -467,48 +467,63 @@ - (void)testEnumeratingConfigResults {
467467
}];
468468
}
469469

470-
- (void)testFetch3pNamespaceUpdatesExperiments {
470+
- (void)testFetchAndActivate3pNamespaceUpdatesExperiments {
471471
[[_experimentMock expect] updateExperimentsWithResponse:[OCMArg any]];
472472

473473
XCTestExpectation *expectation = [self
474-
expectationWithDescription:
475-
[NSString
476-
stringWithFormat:@"Fetch call for 'firebase' namespace updates experiment data"]];
474+
expectationWithDescription:[NSString stringWithFormat:@"FetchAndActivate call for 'firebase' "
475+
@"namespace updates experiment data"]];
477476
XCTAssertEqual(_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
478477
FIRRemoteConfigFetchStatusNoFetchYet);
479-
FIRRemoteConfigFetchCompletion fetchCompletion =
480-
^void(FIRRemoteConfigFetchStatus status, NSError *error) {
478+
479+
FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion =
480+
^void(FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
481+
XCTAssertEqual(status, FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote);
482+
XCTAssertNil(error);
483+
481484
XCTAssertEqual(self->_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
482485
FIRRemoteConfigFetchStatusSuccess);
483-
XCTAssertNil(error);
486+
XCTAssertNotNil(self->_configInstances[RCNTestRCInstanceDefault].lastFetchTime);
487+
XCTAssertGreaterThan(
488+
self->_configInstances[RCNTestRCInstanceDefault].lastFetchTime.timeIntervalSince1970, 0,
489+
@"last fetch time interval should be set.");
484490
[expectation fulfill];
485491
};
486-
[_configInstances[RCNTestRCInstanceDefault] fetchWithExpirationDuration:43200
487-
completionHandler:fetchCompletion];
492+
493+
[_configInstances[RCNTestRCInstanceDefault]
494+
fetchAndActivateWithCompletionHandler:fetchAndActivateCompletion];
488495
[self waitForExpectationsWithTimeout:_expectationTimeout
489496
handler:^(NSError *error) {
490497
XCTAssertNil(error);
491498
}];
492499
}
493500

494-
- (void)testFetchOtherNamespaceDoesntUpdateExperiments {
501+
- (void)testFetchAndActivateOtherNamespaceDoesntUpdateExperiments {
495502
[[_experimentMock reject] updateExperimentsWithResponse:[OCMArg any]];
496503

497-
XCTestExpectation *expectation =
498-
[self expectationWithDescription:
499-
[NSString stringWithFormat:@"Fetch call for namespace other than 'firebase' "
500-
@"doesn't update experiment data"]];
504+
XCTestExpectation *expectation = [self
505+
expectationWithDescription:
506+
[NSString stringWithFormat:@"FetchAndActivate call for namespace other than 'firebase' "
507+
@"doesn't update experiment data"]];
501508
XCTAssertEqual(_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
502509
FIRRemoteConfigFetchStatusNoFetchYet);
503-
FIRRemoteConfigFetchCompletion fetchCompletion =
504-
^void(FIRRemoteConfigFetchStatus status, NSError *error) {
510+
511+
FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion =
512+
^void(FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
513+
XCTAssertEqual(status, FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote);
514+
XCTAssertNil(error);
515+
505516
XCTAssertEqual(self->_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
506517
FIRRemoteConfigFetchStatusSuccess);
507-
XCTAssertNil(error);
518+
XCTAssertNotNil(self->_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchTime);
519+
XCTAssertGreaterThan(self->_configInstances[RCNTestRCInstanceSecondNamespace]
520+
.lastFetchTime.timeIntervalSince1970,
521+
0, @"last fetch time interval should be set.");
508522
[expectation fulfill];
509523
};
510-
[_configInstances[RCNTestRCInstanceSecondNamespace] fetchWithExpirationDuration:43200
511-
completionHandler:fetchCompletion];
524+
525+
[_configInstances[RCNTestRCInstanceSecondNamespace]
526+
fetchAndActivateWithCompletionHandler:fetchAndActivateCompletion];
512527
[self waitForExpectationsWithTimeout:_expectationTimeout
513528
handler:^(NSError *error) {
514529
XCTAssertNil(error);

0 commit comments

Comments
 (0)