mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Realtime rc dev (#9807)
* Remove commits from non-CLA account. Move TypeDef to private RCNRealtimeConfig file.
* Remove completion handler typedef
* Format file
* Update listener registration description
* Realtime rc dev (#9835)
* Remove commits from non-CLA account. Move TypeDef to private RCNRealtimeConfig file.
* Remove completion handler typedef
* Format file
* Update listener registration description
* Add http streaming and auto fetch. Also add template version number to cache for autofetch.
* Format file.
* Add unit tests
* Format files
* fix test
* update test and header file
* Change templateVersionNumber to ivar
* Fix async tests and update NSDictionary changes
* Format file
* Update fetch time
* remove define header
* Wrap auto fetch in async queue
* Add auto fetch test
* Change template version extraction check.
* Change realtime error code to start at 8001
* Realtime rc dev (#9914)
* Remove commits from non-CLA account. Move TypeDef to private RCNRealtimeConfig file.
* Remove completion handler typedef
* Format file
* Update listener registration description
* Add http streaming and auto fetch. Also add template version number to cache for autofetch.
* Format file.
* Add unit tests
* Format files
* fix test
* update test and header file
* Change templateVersionNumber to ivar
* Fix async tests and update NSDictionary changes
* Format file
* Update fetch time
* remove define header
* Add http stream retry and background change listener.
* Wrap auto fetch in async queue
* Expose realtime method in public
* Update comments
* Add auto fetch test
* Change template version extraction check.
* Change realtime error code to start at 8001
* Change from NSTimer to dispatch. Add flag to guard against retrying.
* Format and add comments.
* Update tests
* Qdpham13 patch 1 (#9913)
* Delete .SecondApp-GoogleService-Info.plist
* Delete SecondApp-GoogleService-Info.plist
* Delete GoogleService-Info.plist
* Delete SecondApp-GoogleService-Info.plist
* Update ViewController.m
* Delete clang-format directory
* format
* Change to NSExtensionHostWillEnterForegroundNotification
* Change to UIApplicationWillEnterForegroundNotification
* add import
* Remove import, use string literal instead of UIKit enum
* add test for new public method
* Update template version number retrieval function and update delay
* Fix test
* Fix test
* Update retry seconds and fetch interval seconds
* Update ddos to DDoS
* Update variable according to style guide.
* Replace NSLog with kFIRLoggerRemoteConfig (#10062)
* Replace NSLog with kFIRLoggerRemoteConfig
* Remove logs and change others from info to debug.
* update log messages.
* Format files
* Realtime rc failsafe (#10067)
* Add failsafe logic to request, response and application logic.
* Update flag name and conditions.
* Format file
* Add check for template version number
* Format files
* Changes based on PR comments
* move response parsing logic to separate function and add test for failsafe flag
* Update based on PR comments and add method to propagate error to listeners in queue.
* Realtime rc merge patch v1 (#10089)
* Fix foreground reconnection naming, add background check and flag, add check to see if fetch is currently in progress.
* Add check so fetches come only when the template version is greater than the current one.
* Format file changes
* Add debug log
* Make changes based on PR comments.
* Resolve failsafe changes
* Updating instance var names
* change template version check for auto fetch from >= to >
* Cherry-pick #10123 into Firebase 9.5.0
* [RC] Fix retry logic to respect max retry count (#10143)
* Fix retry logic to respect max retry count
* Rename to isRequestInProgress
* Save template version in settings (#10162)
* Save template version in settings
* Format files
* set last template version to 0
* Store template version in userDefaults instead of deviceContents
* return nil for unsuccessful fetches
* fix typo
* Realtime rc no change (#10188)
* Save template version in settings
* Format files
* set last template version to 0
* Store template version in userDefaults instead of deviceContents
* return nil for unsuccessful fetches
* fix typo
* put addEtagToHeader flag to fetch and propagate it to surrounding functions
* Add excludeEtagHeaderForRealtime flag to RCNConfigFetch
* Update mocks for Swift test
* Fix flag
* Add commentting
* reconcile master branch merge conflicts
* Revert "Realtime rc no change (#10188)" (#10346)
This reverts commit abe7939602.
In part of implementing a different solution.
* Add Http status check to Realtime stream (#10406)
* Check status code before retrying
* Change time out to 5 and a half minutes
* Throw exception if unable to establish connection due to non-retryable status code
* Format file
* Replace old realtime exceptions with new exceptions (#10482)
* Replace old realtime exceptions with new exceptions
* Fix word type
* Realtime RC Fetch ID (#10499)
* Add Realtime specific fetch method and fetch type header changes
* Add test
* Add comments and format
* Fix tests
* Update fetch header name
* Update tests and edit realtime fetch name and params
* refactor remainingAttempts var
* Realtime rc backoff (#10483)
* Change Realtime back off to use same system as Fetch and persist backoff state
* format and fix merge conflict
* Save retry count along with other throttling metadata
* Update var name
* Fix naming
* Return ConfigUpdate to realtime listeners (#10578)
* diff fetched and active config on realtime fetch
* Some refactoring and added tests
* Revert some unrelated changes to fetch
* Fix formatting
* Update branch and fix swift tests
* Rename updatedParams to updatedKeys (#10683)
* Update Realtime RC service URL. (#10713)
* Compare p13n metadata values as dictionaries. (#10756)
* Realtime RC 1P Bug Fix: Add checks for retryHttpConnection method (#10770)
* Add checks to retry method
* Move background check to beginning of retry
* Capitalize FetchType header (#10774)
* Remove Fetch Duplicate error and fix API misuse error (#10814)
* Remove fetch duplicate error
* Move completionHandler to bottom of didReceiveData
* Remove unused var
* Return Server produced error if Http status code is 403 (#10844)
* Add API message to enable Realtime
* Update error message parsing to return error message from backend
* Format file
* Add comment and remove unnecessary string
* Format and update error checks
* Change matcher string
* Update matcher string
* Address PR comments (#10845)
* Address PR comments
* Add Realtime Swift mocks
* Remove unnecessary mocks
* Format files
* Format tests
* Add Realtime mock
* Add missing quote
* Fix bugs
* Remove import
* Update import
* Change import
* Don't make connection call for Realtime mock
* Move around import of RCNConfigSettings
* Fix andDo
* Update test
* Add mockedRealtime flags
* trigger integration test
* Add integration and unit test
* change constant value
* Add new RC key
* Update update
* Remove deleted item
* Add registration removal
* Fix and format files
* remove semicolon
* Update error check
* remove space
* Update capitalization
* Add space
* Remove spaces
* remove more spaces
* Remove comment and add swift name
* format
* Add tests and sampleApp changes for updatedKeys (#10879)
* Update tests and sample app
* change key name
* remove unused var
* Add comment
* update sampleApp comments
* Update comments for public methods
* Update backoff commenting
* Add changelog entry for real-time updates. (#10942)
* Add changelog entry for RC real time updates.
* Hyphenation.
* Change doc references to hyphenate real-time (#10948)
* Change doc references to hyphenate real-time
* Run formatter.
* Re-word real-time paragraph to flow better.
---------
Co-authored-by: Andrew Heard <andrew@wizheard.com>
Co-authored-by: karenyz <58443706+karenyz@users.noreply.github.com>
Co-authored-by: Karen Zeng <karenzeng@google.com>
Co-authored-by: Dana Silver <dsilver1221@gmail.com>
Co-authored-by: Dana Silver <danasilver@google.com>
298 lines
9.9 KiB
Swift
298 lines
9.9 KiB
Swift
// Copyright 2020 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 FirebaseCore
|
|
@testable import FirebaseRemoteConfig
|
|
|
|
import XCTest
|
|
|
|
class APITests: APITestBase {
|
|
func testFetchThenActivate() {
|
|
let expectation = self.expectation(description: #function)
|
|
config.fetch { status, error in
|
|
if let error = error {
|
|
XCTFail("Fetch Error \(error)")
|
|
}
|
|
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
|
|
self.config.activate { _, error in
|
|
XCTAssertNil(error)
|
|
XCTAssertEqual(self.config[Constants.key1].stringValue, Constants.value1)
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
func testFetchWithExpirationThenActivate() {
|
|
let expectation = self.expectation(description: #function)
|
|
config.fetch(withExpirationDuration: 0) { status, error in
|
|
if let error = error {
|
|
XCTFail("Fetch Error \(error)")
|
|
}
|
|
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
|
|
self.config.activate { _, error in
|
|
XCTAssertNil(error)
|
|
XCTAssertEqual(self.config[Constants.key1].stringValue, Constants.value1)
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
func testFetchAndActivate() {
|
|
let expectation = self.expectation(description: #function)
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertEqual(status, .successFetchedFromRemote)
|
|
if let error = error {
|
|
XCTFail("Fetch and Activate Error \(error)")
|
|
}
|
|
XCTAssertEqual(self.config[Constants.key1].stringValue, Constants.value1)
|
|
expectation.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
// Test New API.
|
|
// Contrast with testChangedActivateWillNotFlag in FakeConsole.swift.
|
|
func testUnchangedActivateWillFlag() {
|
|
let expectation = self.expectation(description: #function)
|
|
config.fetch { status, error in
|
|
if let error = error {
|
|
XCTFail("Fetch Error \(error)")
|
|
}
|
|
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
|
|
self.config.activate { changed, error in
|
|
XCTAssertTrue(!APITests.useFakeConfig || changed)
|
|
XCTAssertNil(error)
|
|
XCTAssertEqual(self.config[Constants.key1].stringValue, Constants.value1)
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
waitForExpectations()
|
|
let expectation2 = self.expectation(description: #function + "2")
|
|
config.fetch { status, error in
|
|
if let error = error {
|
|
XCTFail("Fetch Error \(error)")
|
|
}
|
|
XCTAssertEqual(status, RemoteConfigFetchStatus.success)
|
|
self.config.activate { changed, error in
|
|
XCTAssertFalse(changed)
|
|
XCTAssertNil(error)
|
|
XCTAssertEqual(self.config[Constants.key1].stringValue, Constants.value1)
|
|
expectation2.fulfill()
|
|
}
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
func testFetchAndActivateUnchangedConfig() throws {
|
|
guard APITests.useFakeConfig == false else { return }
|
|
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
XCTAssertEqual(config.settings.minimumFetchInterval, 0)
|
|
|
|
let serialQueue = DispatchQueue(label: "\(#function)Queue")
|
|
let group = DispatchGroup()
|
|
group.enter()
|
|
serialQueue.async {
|
|
// Represents pre-fetch occurring sometime in past.
|
|
self.config.fetch { status, error in
|
|
XCTAssertNil(error, "Fetch Error \(error!)")
|
|
XCTAssertEqual(status, .success)
|
|
group.leave()
|
|
}
|
|
}
|
|
|
|
serialQueue.async {
|
|
group.wait()
|
|
group.enter()
|
|
// Represents a `fetchAndActivate` being made to pull latest changes from Remote Config.
|
|
self.config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
// Since no updates to remote config have occurred we use the `.successUsingPreFetchedData`.
|
|
// The behavior of the next test changed in Firebase 7.0.0.
|
|
// It's an open question which is correct, but it should only
|
|
// be changed in a major release.
|
|
// See https://github.com/firebase/firebase-ios-sdk/pull/8788
|
|
// XCTAssertEqual(status, .successUsingPreFetchedData)
|
|
XCTAssertEqual(status, .successFetchedFromRemote)
|
|
// The `lastETagUpdateTime` should either be older or the same time as `lastFetchTime`.
|
|
if let lastFetchTime = try? XCTUnwrap(self.config.lastFetchTime) {
|
|
XCTAssertLessThanOrEqual(Double(self.config.settings.lastETagUpdateTime),
|
|
Double(lastFetchTime.timeIntervalSince1970))
|
|
} else {
|
|
XCTFail("Could not unwrap lastFetchTime.")
|
|
}
|
|
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
|
|
waitForExpectations()
|
|
}
|
|
|
|
// MARK: - RemoteConfigRealtime Tests
|
|
|
|
func testRealtimeRemoteConfigFakeConsole() {
|
|
guard APITests.useFakeConfig == true else { return }
|
|
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
let registration = config.addOnConfigUpdateListener { RemoteConfigUpdate, Error in
|
|
XCTAssertNil(Error, "Realtime error \(Error!)")
|
|
XCTAssertNotNil(RemoteConfigUpdate)
|
|
|
|
expectation.fulfill()
|
|
}
|
|
|
|
waitForExpectations()
|
|
registration.remove()
|
|
}
|
|
|
|
func testRealtimeRemoteConfigRealConsole() {
|
|
guard APITests.useFakeConfig == false else { return }
|
|
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
let registration = config.addOnConfigUpdateListener { RemoteConfigUpdate, Error in
|
|
XCTAssertNil(Error, "Realtime error \(Error!)")
|
|
XCTAssertNotNil(RemoteConfigUpdate)
|
|
XCTAssertNotNil(RemoteConfigUpdate?.updatedKeys.contains(Constants.jedi))
|
|
expectation.fulfill()
|
|
}
|
|
|
|
console.updateRemoteConfigValue(Constants.yoda, forKey: Constants.jedi)
|
|
|
|
waitForExpectations()
|
|
registration.remove()
|
|
}
|
|
|
|
// MARK: - RemoteConfigConsole Tests
|
|
|
|
func testFetchConfigThenUpdateConsoleThenFetchAgain() {
|
|
guard APITests.useFakeConfig == false else { return }
|
|
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
if let configValue = self.config.configValue(forKey: Constants.jedi).stringValue {
|
|
XCTAssertEqual(configValue, Constants.obiwan)
|
|
} else {
|
|
XCTFail("Could not unwrap config value for key: \(Constants.jedi)")
|
|
}
|
|
expectation.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
|
|
// Synchronously update the console.
|
|
console.updateRemoteConfigValue(Constants.yoda, forKey: Constants.jedi)
|
|
|
|
let expectation2 = self.expectation(description: #function + "2")
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
if let configValue = self.config.configValue(forKey: Constants.jedi).stringValue {
|
|
XCTAssertEqual(configValue, Constants.yoda)
|
|
} else {
|
|
XCTFail("Could not unwrap config value for key: \(Constants.jedi)")
|
|
}
|
|
|
|
expectation2.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
func testFetchConfigThenAddValueOnConsoleThenFetchAgain() {
|
|
guard APITests.useFakeConfig == false else { return }
|
|
|
|
// Ensure no Sith Lord has been written to Remote Config yet.
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
XCTAssertTrue(self.config.configValue(forKey: Constants.sith).dataValue.isEmpty)
|
|
|
|
expectation.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
|
|
// Synchronously update the console
|
|
console.updateRemoteConfigValue(Constants.darthSidious, forKey: Constants.sith)
|
|
|
|
// Verify the Sith Lord can now be fetched from Remote Config.
|
|
let expectation2 = self.expectation(description: #function + "2")
|
|
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
if let configValue = self.config.configValue(forKey: Constants.sith).stringValue {
|
|
XCTAssertEqual(configValue, Constants.darthSidious)
|
|
} else {
|
|
XCTFail("Could not unwrap config value for key: \(Constants.sith)")
|
|
}
|
|
|
|
expectation2.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
func testFetchConfigThenDeleteValueOnConsoleThenFetchAgain() {
|
|
guard APITests.useFakeConfig == false else { return }
|
|
|
|
let expectation = self.expectation(description: #function)
|
|
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
if let configValue = self.config.configValue(forKey: Constants.jedi).stringValue {
|
|
XCTAssertEqual(configValue, Constants.obiwan)
|
|
} else {
|
|
XCTFail("Could not unwrap config value for key: \(Constants.jedi)")
|
|
}
|
|
expectation.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
|
|
// Synchronously delete value on the console.
|
|
console.removeRemoteConfigValue(forKey: Constants.jedi)
|
|
|
|
let expectation2 = self.expectation(description: #function + "2")
|
|
config.fetchAndActivate { status, error in
|
|
XCTAssertNil(error, "Fetch & Activate Error \(error!)")
|
|
|
|
XCTAssertTrue(self.config.configValue(forKey: Constants.jedi).dataValue.isEmpty,
|
|
"Remote config should have been deleted.")
|
|
|
|
expectation2.fulfill()
|
|
}
|
|
waitForExpectations()
|
|
}
|
|
|
|
// MARK: - Private Helpers
|
|
|
|
private func waitForExpectations() {
|
|
let kTestTimeout = 10.0
|
|
waitForExpectations(timeout: kTestTimeout,
|
|
handler: { error in
|
|
if let error = error {
|
|
print(error)
|
|
}
|
|
})
|
|
}
|
|
}
|