Quellcode durchsuchen

Modify activate path to only update experiments for firebase namespace (#9972)

* Modify activate path to only update experiments for firebase namespace

* Add changelog
karenyz vor 3 Jahren
Ursprung
Commit
d5637c4cd7

+ 1 - 0
FirebaseRemoteConfig/CHANGELOG.md

@@ -1,6 +1,7 @@
 # 9.3.0
 - [changed] Arrays and Dictionaries are now supported when initializing defaults from a
   plist. (#8306)
+- [fixed] Activate calls will only update experiment data for `firebase` namespace to ensure correct experiment exposures. (#9972)
 
 # 9.0.0
 - [changed] The `remoteConfig()` singleton now throws an exception when called before

+ 14 - 2
FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

@@ -316,13 +316,25 @@ typedef void (^FIRRemoteConfigActivateChangeCompletion)(BOOL changed, NSError *_
     strongSelf->_settings.lastApplyTimeInterval = [[NSDate date] timeIntervalSince1970];
     FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000069", @"Config activated.");
     [strongSelf->_configContent activatePersonalization];
-    [strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
+
+    // Update experiments only for 3p namespace
+    NSString *namespace = [strongSelf->_FIRNamespace
+        substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
+    if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
+      [strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
+        if (completion) {
+          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            completion(YES, nil);
+          });
+        }
+      }];
+    } else {
       if (completion) {
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           completion(YES, nil);
         });
       }
-    }];
+    }
   };
   dispatch_async(_queue, applyBlock);
 }

+ 34 - 19
FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m

@@ -467,48 +467,63 @@ typedef NS_ENUM(NSInteger, RCNTestRCInstance) {
                                }];
 }
 
-- (void)testFetch3pNamespaceUpdatesExperiments {
+- (void)testFetchAndActivate3pNamespaceUpdatesExperiments {
   [[_experimentMock expect] updateExperimentsWithResponse:[OCMArg any]];
 
   XCTestExpectation *expectation = [self
-      expectationWithDescription:
-          [NSString
-              stringWithFormat:@"Fetch call for 'firebase' namespace updates experiment data"]];
+      expectationWithDescription:[NSString stringWithFormat:@"FetchAndActivate call for 'firebase' "
+                                                            @"namespace updates experiment data"]];
   XCTAssertEqual(_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
                  FIRRemoteConfigFetchStatusNoFetchYet);
-  FIRRemoteConfigFetchCompletion fetchCompletion =
-      ^void(FIRRemoteConfigFetchStatus status, NSError *error) {
+
+  FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion =
+      ^void(FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
+        XCTAssertEqual(status, FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote);
+        XCTAssertNil(error);
+
         XCTAssertEqual(self->_configInstances[RCNTestRCInstanceDefault].lastFetchStatus,
                        FIRRemoteConfigFetchStatusSuccess);
-        XCTAssertNil(error);
+        XCTAssertNotNil(self->_configInstances[RCNTestRCInstanceDefault].lastFetchTime);
+        XCTAssertGreaterThan(
+            self->_configInstances[RCNTestRCInstanceDefault].lastFetchTime.timeIntervalSince1970, 0,
+            @"last fetch time interval should be set.");
         [expectation fulfill];
       };
-  [_configInstances[RCNTestRCInstanceDefault] fetchWithExpirationDuration:43200
-                                                        completionHandler:fetchCompletion];
+
+  [_configInstances[RCNTestRCInstanceDefault]
+      fetchAndActivateWithCompletionHandler:fetchAndActivateCompletion];
   [self waitForExpectationsWithTimeout:_expectationTimeout
                                handler:^(NSError *error) {
                                  XCTAssertNil(error);
                                }];
 }
 
-- (void)testFetchOtherNamespaceDoesntUpdateExperiments {
+- (void)testFetchAndActivateOtherNamespaceDoesntUpdateExperiments {
   [[_experimentMock reject] updateExperimentsWithResponse:[OCMArg any]];
 
-  XCTestExpectation *expectation =
-      [self expectationWithDescription:
-                [NSString stringWithFormat:@"Fetch call for namespace other than 'firebase' "
-                                           @"doesn't update experiment data"]];
+  XCTestExpectation *expectation = [self
+      expectationWithDescription:
+          [NSString stringWithFormat:@"FetchAndActivate call for namespace other than 'firebase' "
+                                     @"doesn't update experiment data"]];
   XCTAssertEqual(_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
                  FIRRemoteConfigFetchStatusNoFetchYet);
-  FIRRemoteConfigFetchCompletion fetchCompletion =
-      ^void(FIRRemoteConfigFetchStatus status, NSError *error) {
+
+  FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion =
+      ^void(FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
+        XCTAssertEqual(status, FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote);
+        XCTAssertNil(error);
+
         XCTAssertEqual(self->_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchStatus,
                        FIRRemoteConfigFetchStatusSuccess);
-        XCTAssertNil(error);
+        XCTAssertNotNil(self->_configInstances[RCNTestRCInstanceSecondNamespace].lastFetchTime);
+        XCTAssertGreaterThan(self->_configInstances[RCNTestRCInstanceSecondNamespace]
+                                 .lastFetchTime.timeIntervalSince1970,
+                             0, @"last fetch time interval should be set.");
         [expectation fulfill];
       };
-  [_configInstances[RCNTestRCInstanceSecondNamespace] fetchWithExpirationDuration:43200
-                                                                completionHandler:fetchCompletion];
+
+  [_configInstances[RCNTestRCInstanceSecondNamespace]
+      fetchAndActivateWithCompletionHandler:fetchAndActivateCompletion];
   [self waitForExpectationsWithTimeout:_expectationTimeout
                                handler:^(NSError *error) {
                                  XCTAssertNil(error);