Skip to content

Commit

Permalink
Address comments and improve PINCacheTests (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy authored and garrettmoon committed Nov 18, 2016
1 parent 48031ad commit e1109b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions PINCache/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ + (NSLock *)sharedLock

+ (NSURL *)sharedTrashURL
{
NSURL *trashURL;
NSURL *trashURL = nil;

[[PINDiskCache sharedLock] lock];
if (_sharedTrashURL == nil) {
Expand Down Expand Up @@ -332,8 +332,11 @@ + (BOOL)moveItemAtURLToTrash:(NSURL *)itemURL
+ (void)emptyTrash
{
dispatch_async([PINDiskCache sharedTrashQueue], ^{
NSURL *trashURL;

NSURL *trashURL = nil;

// If _sharedTrashURL is unset, there's nothing left to do because it hasn't been accessed and therefore items haven't been added to it.
// If it is set, we can just remove it.
// We also need to nil out _sharedTrashURL so that a new one will be created if there's an attempt to move a new file to the trash.
[[PINDiskCache sharedLock] lock];
if (_sharedTrashURL != nil) {
trashURL = _sharedTrashURL;
Expand Down
12 changes: 9 additions & 3 deletions tests/PINCacheTests/PINCacheTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ - (void)setUp

- (void)tearDown
{
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);

[self.cache removeAllObjects];

// Disk cache needs a bit more time to clean up its trash
sleep(1);

// Wait for disk cache to clean up its trash
dispatch_async([PINDiskCache sharedTrashQueue], ^{
dispatch_group_leave(group);
});
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);

self.cache = nil;

XCTAssertNil(self.cache, @"test cache did not deallocate");
Expand Down

0 comments on commit e1109b2

Please sign in to comment.