Permalink
Browse files

[ios-sdk] Fix cache unit test.

Summary:
Cache unit test was not waiting for both queues to flush before attempting to use cached files, so it would experience
intermittent failures due to a race condition. Added a sync call in two places.

Test Plan:
- Ran unit tests many, many times.

Revert Plan:

Reviewers: jacl

Reviewed By: jacl

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D579077
  • Loading branch information...
1 parent 3e8b54c commit 02072925e39ee077090726b7ddb229cf635728ef @clang13 clang13 committed Sep 19, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/tests/FBCacheTests.m
View
@@ -113,7 +113,7 @@ - (void)cacheIndex:(FBCacheIndex*)cacheIndex
{
NSString* filePath = [_dataCachePath stringByAppendingPathComponent:name];
dispatch_async(_fileQueue, ^{
- [[NSFileManager defaultManager]
+ [[NSFileManager defaultManager]
removeItemAtPath:filePath
error:nil];
});
@@ -237,6 +237,7 @@ - (void)testDataPersistence
// Wait for the queue to finish
dispatch_sync(cacheIndex.databaseQueue, ^{});
+ dispatch_sync(_fileQueue, ^{});
STAssertEquals(
cacheIndex.currentDiskUsage,
fileSize*numberOfFiles,
@@ -333,10 +334,11 @@ - (void)testDeletingUsedData
NSString *filePath = [tempFolder
stringByAppendingPathComponent:fileName];
- // Flush the write queue
+ // Flush the write queues
dispatch_sync(cacheIndex.databaseQueue, ^{});
+ dispatch_sync(_fileQueue, ^{});
- NSData *dataFromFile = [NSData
+ NSData *dataFromFile = [NSData
dataWithContentsOfFile:filePath
options:NSDataReadingMappedAlways | NSDataReadingUncached
error:nil];
@@ -356,7 +358,7 @@ - (void)testDeletingUsedData
[cacheIndex removeEntryForKey:@"test1"];
dispatch_sync(cacheIndex.databaseQueue, ^{});
dispatch_sync(_fileQueue, ^{});
-
+
BOOL fileExists = [[NSFileManager defaultManager]
fileExistsAtPath:filePath];
STAssertFalse(fileExists, @"File wasn't deleted at %@", filePath);

0 comments on commit 0207292

Please sign in to comment.