Skip to content

Commit

Permalink
Fix Performance Unit Test Warnings around UserDefaults (#13787)
Browse files Browse the repository at this point in the history
  • Loading branch information
samedson authored Oct 3, 2024
1 parent 8738b84 commit ba8623f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <XCTest/XCTest.h>

#import <GoogleUtilities/GULUserDefaults.h>

#import "FirebasePerformance/Sources/Common/FPRConstants.h"

#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
Expand All @@ -30,6 +32,10 @@ @interface FPRConfigurationsTest : XCTestCase

@implementation FPRConfigurationsTest

- (GULUserDefaults *_Nonnull)makeEmptyUserDefaults {
return [[GULUserDefaults alloc] init];
}

/** Validates if instance creation works. */
- (void)testInstanceCreation {
XCTAssertNotNil([[FPRConfigurations alloc] initWithSources:FPRConfigurationSourceNone]);
Expand Down Expand Up @@ -78,7 +84,7 @@ - (void)testOverridesForDiagnosticsEnabled {
FPRConfigurations *configurations =
[[FPRConfigurations alloc] initWithSources:FPRConfigurationSourceRemoteConfig];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configurations.userDefaults = userDefaults;

XCTAssertFalse(configurations.diagnosticsEnabled);
Expand All @@ -101,7 +107,7 @@ - (void)testTraceSamplingRateRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

[configFlags resetCache];
Expand All @@ -126,7 +132,7 @@ - (void)testNetworkRequestSamplingRateRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

[configFlags resetCache];
Expand All @@ -151,7 +157,7 @@ - (void)testSessionSamplingRateRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

[configFlags resetCache];
Expand All @@ -176,7 +182,7 @@ - (void)testSessionSamplingRatePlistOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

[configFlags resetCache];
Expand Down Expand Up @@ -205,7 +211,7 @@ - (void)testLogSourceRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

[configFlags resetCache];
Expand Down Expand Up @@ -239,7 +245,7 @@ - (void)testDisabledSDKVersionsConfigResolveSuccessful {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSSet<NSString *> *versionSet =
Expand Down Expand Up @@ -269,7 +275,7 @@ - (void)testDisabledSDKVersionsDisablesSDK {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand Down Expand Up @@ -299,7 +305,7 @@ - (void)testSDKEnabledFlag {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand All @@ -325,7 +331,7 @@ - (void)testPlistOverridesSDKEnabledFlag {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand All @@ -351,7 +357,7 @@ - (void)testForegroundRateLimitingTraceCountRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey =
Expand All @@ -375,7 +381,7 @@ - (void)testBackgroundRateLimitingTraceCountRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey =
Expand All @@ -399,7 +405,7 @@ - (void)testForegroundRateLimitingNetworkCountRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString
Expand All @@ -423,7 +429,7 @@ - (void)testBackgroundRateLimitingNetworkCountRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString
Expand All @@ -447,7 +453,7 @@ - (void)testRateLimitingDurationRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey =
Expand Down Expand Up @@ -477,7 +483,7 @@ - (void)testGaugeCollectionFrequencyRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKeyCPUFg =
Expand Down Expand Up @@ -526,7 +532,7 @@ - (void)testSessionMaxLengthDurationRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey =
Expand All @@ -549,7 +555,7 @@ - (void)testPrewarmDetectionRemoteConfigOverrides {
configurations.remoteConfigFlags = configFlags;
configFlags.lastFetchedTime = [NSDate date];

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [self makeEmptyUserDefaults];
configFlags.userDefaults = userDefaults;

NSString *configKey =
Expand Down
4 changes: 3 additions & 1 deletion FirebasePerformance/Tests/Unit/FPRNetworkTraceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <XCTest/XCTest.h>

#import <GoogleUtilities/GULUserDefaults.h>

#import "FirebasePerformance/Sources/AppActivity/FPRSessionManager.h"
#import "FirebasePerformance/Sources/Common/FPRConstants.h"
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
Expand Down Expand Up @@ -141,7 +143,7 @@ - (void)testTraceCreationWhenSDKFlagEnabled {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
configurations.remoteConfigFlags = configFlags;

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *userDefaults = [[GULUserDefaults alloc] init];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand Down
4 changes: 3 additions & 1 deletion FirebasePerformance/Tests/Unit/Gauges/FPRGaugeManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <XCTest/XCTest.h>

#import <GoogleUtilities/GULUserDefaults.h>

#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h"
Expand Down Expand Up @@ -91,7 +93,7 @@ - (void)testGaugeCollectionDisabledWhenSDKFlagDisabled {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
configurations.remoteConfigFlags = configFlags;

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *_Nonnull userDefaults = [[GULUserDefaults alloc] init];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <XCTest/XCTest.h>

#import <GoogleUtilities/GULUserDefaults.h>

#import "FirebasePerformance/Sources/Common/FPRConstants.h"
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
Expand Down Expand Up @@ -118,7 +120,7 @@ - (void)testMetricCreationWhenSDKFlagEnabled {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
configurations.remoteConfigFlags = configFlags;

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *userDefaults = [[GULUserDefaults alloc] init];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand Down
4 changes: 3 additions & 1 deletion FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import <XCTest/XCTest.h>

#import <GoogleUtilities/GULUserDefaults.h>

#import "FirebasePerformance/Sources/AppActivity/FPRAppActivityTracker.h"
#import "FirebasePerformance/Sources/AppActivity/FPRSessionManager.h"
#import "FirebasePerformance/Sources/Common/FPRConstants.h"
Expand Down Expand Up @@ -99,7 +101,7 @@ - (void)testTraceCreationWhenSDKFlagEnabled {
[[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig];
configurations.remoteConfigFlags = configFlags;

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
GULUserDefaults *userDefaults = [[GULUserDefaults alloc] init];
configFlags.userDefaults = userDefaults;

NSString *configKey = [NSString stringWithFormat:@"%@.%@", kFPRConfigPrefix, @"fpr_enabled"];
Expand Down

0 comments on commit ba8623f

Please sign in to comment.