@@ -127,33 +127,27 @@ - (BOOL)writeSettings:(const NSString *)settings
127127- (void )cacheSettingsWithGoogleAppID : (NSString *)googleAppID
128128 currentTimestamp : (NSTimeInterval )currentTimestamp
129129 expectedRemoveCount : (NSInteger )expectedRemoveCount {
130+ self.fileManager .removeExpectation = [[XCTestExpectation alloc ]
131+ initWithDescription: @" FIRCLSMockFileManager.removeExpectation.cache" ];
130132 self.fileManager .removeCount = 0 ;
131-
132- XCTestExpectation *expectation =
133- [self expectationForNotification: FIRCLSMockFileManagerDidRemoveItemNotification
134- object: nil
135- handler: nil ];
136- expectation.expectedFulfillmentCount = expectedRemoveCount;
133+ self.fileManager .expectedRemoveCount = expectedRemoveCount;
137134
138135 [self .settings cacheSettingsWithGoogleAppID: googleAppID currentTimestamp: currentTimestamp];
139136
140- [self waitForExpectations: @[ expectation ] timeout: 16.0 ];
137+ [self waitForExpectations: @[ self .fileManager.removeExpectation ] timeout: 1 ];
141138}
142139
143140- (void )reloadFromCacheWithGoogleAppID : (NSString *)googleAppID
144141 currentTimestamp : (NSTimeInterval )currentTimestamp
145142 expectedRemoveCount : (NSInteger )expectedRemoveCount {
143+ self.fileManager .removeExpectation = [[XCTestExpectation alloc ]
144+ initWithDescription: @" FIRCLSMockFileManager.removeExpectation.reload" ];
146145 self.fileManager .removeCount = 0 ;
147-
148- XCTestExpectation *expectation =
149- [self expectationForNotification: FIRCLSMockFileManagerDidRemoveItemNotification
150- object: nil
151- handler: nil ];
152- expectation.expectedFulfillmentCount = expectedRemoveCount;
146+ self.fileManager .expectedRemoveCount = expectedRemoveCount;
153147
154148 [self .settings reloadFromCacheWithGoogleAppID: googleAppID currentTimestamp: currentTimestamp];
155149
156- [self waitForExpectations: @[ expectation ] timeout: 14 .0 ];
150+ [self waitForExpectations: @[ self .fileManager.removeExpectation ] timeout: 5 .0 ];
157151}
158152
159153- (void )testActivatedSettingsCached {
@@ -211,6 +205,10 @@ - (void)testCacheExpiredFromTTL {
211205 [self writeSettings: FIRCLSTestSettingsActivated error: &error];
212206 XCTAssertNil (error, " %@" , error);
213207
208+ // 1 delete for clearing the cache key, plus 2 for the deletes from reloading and clearing the
209+ // cache and cache key
210+ self.fileManager .expectedRemoveCount = 3 ;
211+
214212 NSTimeInterval currentTimestamp = [NSDate timeIntervalSinceReferenceDate ];
215213 [self .settings cacheSettingsWithGoogleAppID: TestGoogleAppID currentTimestamp: currentTimestamp];
216214
@@ -240,6 +238,10 @@ - (void)testCacheExpiredFromBuildInstanceID {
240238 [self writeSettings: FIRCLSTestSettingsActivated error: &error];
241239 XCTAssertNil (error, " %@" , error);
242240
241+ // 1 delete for clearing the cache key, plus 2 for the deletes from reloading and clearing the
242+ // cache and cache key
243+ self.fileManager .expectedRemoveCount = 3 ;
244+
243245 NSTimeInterval currentTimestamp = [NSDate timeIntervalSinceReferenceDate ];
244246 [self .settings cacheSettingsWithGoogleAppID: TestGoogleAppID currentTimestamp: currentTimestamp];
245247
@@ -270,6 +272,10 @@ - (void)testCacheExpiredFromAppVersion {
270272 [self writeSettings: FIRCLSTestSettingsActivated error: &error];
271273 XCTAssertNil (error, " %@" , error);
272274
275+ // 1 delete for clearing the cache key, plus 2 for the deletes from reloading and clearing the
276+ // cache and cache key
277+ self.fileManager .expectedRemoveCount = 3 ;
278+
273279 NSTimeInterval currentTimestamp = [NSDate timeIntervalSinceReferenceDate ];
274280 [self .settings cacheSettingsWithGoogleAppID: TestGoogleAppID currentTimestamp: currentTimestamp];
275281
@@ -296,7 +302,6 @@ - (void)testCacheExpiredFromAppVersion {
296302 XCTAssertEqual (self.settings .errorLogBufferSize , 128000 );
297303}
298304
299- #ifdef FLAKY_TEST
300305- (void )testGoogleAppIDChanged {
301306 NSError *error = nil ;
302307 [self writeSettings: FIRCLSTestSettingsInverse error: &error];
@@ -382,7 +387,7 @@ - (void)testCorruptCache {
382387 // Cache them, and reload. Since it's corrupted we should delete it all
383388 [self cacheSettingsWithGoogleAppID: TestGoogleAppID
384389 currentTimestamp: currentTimestamp
385- expectedRemoveCount: 3 ];
390+ expectedRemoveCount: 2 ];
386391
387392 // Should have default values because we deleted the cache and settingsDictionary
388393 XCTAssertEqual (self.settings .isCacheExpired , YES );
@@ -424,7 +429,6 @@ - (void)testCorruptCacheKey {
424429 XCTAssertEqual (self.settings .onDemandBackoffBase , 1.5 );
425430 XCTAssertEqual (self.settings .onDemandBackoffStepDuration , 6 );
426431}
427- #endif // FLAKY_TEST
428432
429433- (void )testNewReportEndpointSettings {
430434 NSString *settingsJSON =
0 commit comments