diff --git a/Crashlytics/Crashlytics/Models/FIRCLSSettings.h b/Crashlytics/Crashlytics/Models/FIRCLSSettings.h index f122fffd93b..488cc295530 100644 --- a/Crashlytics/Crashlytics/Models/FIRCLSSettings.h +++ b/Crashlytics/Crashlytics/Models/FIRCLSSettings.h @@ -30,8 +30,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; - (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager - appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel - NS_DESIGNATED_INITIALIZER; + appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel; /** * Recreates the settings dictionary by re-reading the settings file from persistent storage. This diff --git a/Crashlytics/Crashlytics/Models/FIRCLSSettings.m b/Crashlytics/Crashlytics/Models/FIRCLSSettings.m index 80c70a48953..b53c44e38d3 100644 --- a/Crashlytics/Crashlytics/Models/FIRCLSSettings.m +++ b/Crashlytics/Crashlytics/Models/FIRCLSSettings.m @@ -40,12 +40,23 @@ @interface FIRCLSSettings () @property(nonatomic) BOOL isCacheKeyExpired; +@property(nonatomic) dispatch_queue_t deletionQueue; + @end @implementation FIRCLSSettings - (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel { + return + [self initWithFileManager:fileManager + appIDModel:appIDModel + deletionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)]; +} + +- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager + appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel + deletionQueue:(dispatch_queue_t)deletionQueue { self = [super init]; if (!self) { return nil; @@ -57,6 +68,8 @@ - (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager _settingsDictionary = nil; _isCacheKeyExpired = NO; + _deletionQueue = deletionQueue; + return self; } @@ -190,9 +203,7 @@ - (NSDictionary *)loadCacheKey { - (void)deleteCachedSettings { __weak FIRCLSSettings *weakSelf = self; -#ifndef FIREBASE_IS_NIGHTLY_TESTING - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ -#endif + dispatch_async(_deletionQueue, ^{ __strong FIRCLSSettings *strongSelf = weakSelf; if ([strongSelf.fileManager fileExistsAtPath:strongSelf.fileManager.settingsFilePath]) { [strongSelf.fileManager removeItemAtPath:strongSelf.fileManager.settingsFilePath]; @@ -200,9 +211,7 @@ - (void)deleteCachedSettings { if ([strongSelf.fileManager fileExistsAtPath:strongSelf.fileManager.settingsCacheKeyPath]) { [strongSelf.fileManager removeItemAtPath:strongSelf.fileManager.settingsCacheKeyPath]; } -#ifndef FIREBASE_IS_NIGHTLY_TESTING }); -#endif @synchronized(self) { self.isCacheKeyExpired = YES; diff --git a/Crashlytics/UnitTests/FIRCLSSettingsTests.m b/Crashlytics/UnitTests/FIRCLSSettingsTests.m index e2bfb58068f..1ef5a58c890 100644 --- a/Crashlytics/UnitTests/FIRCLSSettingsTests.m +++ b/Crashlytics/UnitTests/FIRCLSSettingsTests.m @@ -60,6 +60,10 @@ @interface FIRCLSSettings (Testing) @property(nonatomic, strong) NSDictionary *settingsDictionary; +- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager + appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel + deletionQueue:(dispatch_queue_t)deletionQueue; + @end @interface FIRCLSSettingsTests : XCTestCase @@ -75,7 +79,6 @@ @implementation FIRCLSSettingsTests - (void)setUp { [super setUp]; - _fileManager = [[FIRCLSMockFileManager alloc] init]; _appIDModel = [[FABMockApplicationIdentifierModel alloc] init]; @@ -83,7 +86,11 @@ - (void)setUp { _appIDModel.displayVersion = FIRCLSDefaultMockAppDisplayVersion; _appIDModel.buildVersion = FIRCLSDefaultMockAppBuildVersion; - _settings = [[FIRCLSSettings alloc] initWithFileManager:_fileManager appIDModel:_appIDModel]; + // Inject a higher priority queue for deletion operations to reduce flakes. + _settings = [[FIRCLSSettings alloc] + initWithFileManager:_fileManager + appIDModel:_appIDModel + deletionQueue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)]; } - (void)testDefaultSettings { @@ -134,7 +141,7 @@ - (void)cacheSettingsWithGoogleAppID:(NSString *)googleAppID [self.settings cacheSettingsWithGoogleAppID:googleAppID currentTimestamp:currentTimestamp]; - [self waitForExpectations:@[ self.fileManager.removeExpectation ] timeout:1]; + [self waitForExpectations:@[ self.fileManager.removeExpectation ] timeout:5.0]; } - (void)reloadFromCacheWithGoogleAppID:(NSString *)googleAppID