Skip to content

Commit

Permalink
[ios-sdk] Fix cache unit test.
Browse files Browse the repository at this point in the history
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
Chris Lang committed Sep 20, 2012
1 parent 3e8b54c commit 0207292
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tests/FBCacheTests.m
Expand Up @@ -113,7 +113,7 @@ - (void)cacheIndex:(FBCacheIndex*)cacheIndex
{
NSString* filePath = [_dataCachePath stringByAppendingPathComponent:name];
dispatch_async(_fileQueue, ^{
[[NSFileManager defaultManager]
[[NSFileManager defaultManager]
removeItemAtPath:filePath
error:nil];
});
Expand Down Expand Up @@ -237,6 +237,7 @@ - (void)testDataPersistence

// Wait for the queue to finish
dispatch_sync(cacheIndex.databaseQueue, ^{});
dispatch_sync(_fileQueue, ^{});
STAssertEquals(
cacheIndex.currentDiskUsage,
fileSize*numberOfFiles,
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand Down

0 comments on commit 0207292

Please sign in to comment.