-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Do not activate if fetch returns NO_CHANGE #4260
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -560,6 +560,132 @@ - (void)testFetchConfigsFailed { | |
| }]; | ||
| } | ||
|
|
||
| // Activate should return false if a fetch response returns 200 with NO_CHANGE as the response body. | ||
| - (void)testActivateOnFetchNoChangeStatus { | ||
| // Override the setup values to return back an error status. | ||
| RCNConfigContent *configContent = [[RCNConfigContent alloc] initWithDBManager:_DBManager]; | ||
| // Populate the default, second app, second namespace instances. | ||
| for (int i = 0; i < RCNTestRCNumTotalInstances; i++) { | ||
| NSString *currentAppName = nil; | ||
| FIROptions *currentOptions = nil; | ||
| NSString *currentNamespace = nil; | ||
| switch (i) { | ||
| case RCNTestRCInstanceSecondNamespace: | ||
| currentAppName = RCNTestsDefaultFIRAppName; | ||
| currentOptions = [self firstAppOptions]; | ||
| currentNamespace = RCNTestsPerfNamespace; | ||
| break; | ||
| case RCNTestRCInstanceSecondApp: | ||
| currentAppName = RCNTestsSecondFIRAppName; | ||
| currentOptions = [self secondAppOptions]; | ||
| currentNamespace = FIRNamespaceGoogleMobilePlatform; | ||
| break; | ||
| case RCNTestRCInstanceDefault: | ||
| default: | ||
| currentAppName = RCNTestsDefaultFIRAppName; | ||
| currentOptions = [self firstAppOptions]; | ||
| currentNamespace = RCNTestsFIRNamespace; | ||
| break; | ||
| } | ||
| NSString *fullyQualifiedNamespace = | ||
| [NSString stringWithFormat:@"%@:%@", currentNamespace, currentAppName]; | ||
| RCNUserDefaultsManager *userDefaultsManager = | ||
| [[RCNUserDefaultsManager alloc] initWithAppName:currentAppName | ||
| bundleID:[NSBundle mainBundle].bundleIdentifier | ||
| namespace:fullyQualifiedNamespace]; | ||
| userDefaultsManager.lastFetchTime = 10; | ||
|
|
||
| FIRRemoteConfig *config = | ||
| OCMPartialMock([[FIRRemoteConfig alloc] initWithAppName:currentAppName | ||
| FIROptions:currentOptions | ||
| namespace:currentNamespace | ||
| DBManager:_DBManager | ||
| configContent:configContent | ||
| analytics:nil]); | ||
|
|
||
| _configInstances[i] = config; | ||
| RCNConfigSettings *settings = | ||
| [[RCNConfigSettings alloc] initWithDatabaseManager:_DBManager | ||
| namespace:fullyQualifiedNamespace | ||
| firebaseAppName:currentAppName | ||
| googleAppID:currentOptions.googleAppID]; | ||
| // Start the test with the assumption that we have some data that was fetched and activated. | ||
| settings.lastETag = @"etag1"; | ||
| settings.lastETagUpdateTime = 100; | ||
| settings.lastApplyTimeInterval = 101; | ||
|
|
||
| dispatch_queue_t queue = | ||
| dispatch_queue_create([[NSString stringWithFormat:@"testNoStatusFetchQueue: %d", i] | ||
| cStringUsingEncoding:NSUTF8StringEncoding], | ||
| DISPATCH_QUEUE_SERIAL); | ||
| _configFetch[i] = OCMPartialMock([[RCNConfigFetch alloc] initWithContent:configContent | ||
| DBManager:_DBManager | ||
| settings:settings | ||
|
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. is this format right? Maybe run script/style.sh 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. This is with style.sh. |
||
| analytics:nil | ||
| experiment:nil | ||
| queue:queue | ||
| namespace:fullyQualifiedNamespace | ||
| options:currentOptions]); | ||
|
|
||
| OCMStub([_configFetch[i] fetchAllConfigsWithExpirationDuration:43200 | ||
| completionHandler:OCMOCK_ANY]) | ||
| .andDo(^(NSInvocation *invocation) { | ||
| void (^handler)(FIRRemoteConfigFetchStatus status, NSError *_Nullable error) = nil; | ||
|
|
||
| [invocation getArgument:&handler atIndex:3]; | ||
| [_configFetch[i] fetchWithUserProperties:[[NSDictionary alloc] init] | ||
| completionHandler:handler]; | ||
| }); | ||
|
|
||
| _response[i] = @{@"state" : @"NO_CHANGE"}; | ||
|
|
||
| _responseData[i] = [NSJSONSerialization dataWithJSONObject:_response[i] options:0 error:nil]; | ||
|
|
||
| _URLResponse[i] = | ||
| [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"https://firebase.com"] | ||
| statusCode:200 | ||
| HTTPVersion:nil | ||
| headerFields:@{@"etag" : @"etag1"}]; | ||
|
|
||
| id completionBlock = | ||
| [OCMArg invokeBlockWithArgs:_responseData[i], _URLResponse[i], [NSNull null], nil]; | ||
|
|
||
| OCMExpect([_configFetch[i] URLSessionDataTaskWithContent:[OCMArg any] | ||
| completionHandler:completionBlock]) | ||
| .andReturn(nil); | ||
| [_configInstances[i] updateWithNewInstancesForConfigFetch:_configFetch[i] | ||
| configContent:configContent | ||
| configSettings:settings | ||
| configExperiment:nil]; | ||
| } | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
| // Make the fetch calls for all instances. | ||
| NSMutableArray<XCTestExpectation *> *expectations = | ||
| [[NSMutableArray alloc] initWithCapacity:RCNTestRCNumTotalInstances]; | ||
|
|
||
| for (int i = 0; i < RCNTestRCNumTotalInstances; i++) { | ||
| expectations[i] = [self | ||
| expectationWithDescription: | ||
| [NSString stringWithFormat:@"Test enumerating configs successfully - instance %d", i]]; | ||
| XCTAssertEqual(_configInstances[i].lastFetchStatus, FIRRemoteConfigFetchStatusNoFetchYet); | ||
|
|
||
| // Make sure activate returns false in fetch completion. | ||
| FIRRemoteConfigFetchCompletion fetchCompletion = | ||
| ^void(FIRRemoteConfigFetchStatus status, NSError *error) { | ||
| XCTAssertEqual(_configInstances[i].lastFetchStatus, FIRRemoteConfigFetchStatusSuccess); | ||
| XCTAssertFalse([_configInstances[i] activateFetched]); | ||
| XCTAssertNil(error); | ||
| [expectations[i] fulfill]; | ||
| }; | ||
| [_configInstances[i] fetchWithExpirationDuration:43200 completionHandler:fetchCompletion]; | ||
| } | ||
| [self waitForExpectationsWithTimeout:_expectationTimeout | ||
| handler:^(NSError *error) { | ||
| XCTAssertNil(error); | ||
| }]; | ||
| } | ||
|
|
||
| - (void)testConfigValueForKey { | ||
| NSMutableArray<XCTestExpectation *> *expectations = | ||
| [[NSMutableArray alloc] initWithCapacity:RCNTestRCNumTotalInstances]; | ||
|
|
||
This file contains hidden or 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
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.
should we persist this value? cuz what happened before the current app launch.
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.
good pt. Done.