Permalink
Browse files

Update RKTestFactory to silence logging output during setup/tear down…

… operations. closes #764

* Introduced new logging helpers for silencing components.
* Check for existence of data store at path before firing deletion to avoid log warning on failure.
* Silence logging for reachability and cache during factory initialization of RKClient and RKObjectManager
* Adjust log levels on cache components from info to debug
  • Loading branch information...
1 parent 992bfb9 commit 680ca666d653b18f44a330f5caba7b2800b9af7f @blakewatters blakewatters committed May 24, 2012
Showing with 37 additions and 14 deletions.
  1. +2 −2 Code/CoreData/RKEntityByAttributeCache.m
  2. +7 −1 Code/Support/RKLog.h
  3. +28 −11 Code/Testing/RKTestFactory.m
@@ -99,7 +99,7 @@ - (BOOL)shouldCoerceAttributeToString:(NSString *)attributeValue
- (void)load
{
- RKLogInfo(@"Loading entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
+ RKLogDebug(@"Loading entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:self.entity];
[fetchRequest setResultType:NSManagedObjectIDResultType];
@@ -126,7 +126,7 @@ - (void)load
- (void)flush
{
- RKLogInfo(@"Flushing entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
+ RKLogDebug(@"Flushing entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
self.attributeValuesToObjectIDs = nil;
}
@@ -138,6 +138,12 @@ lcl_configure_by_name("App", level);
} \
} while(false);
+/**
+ Temporarily turns off logging for the given logging component during execution of the block.
+ After the block has finished execution, the logging level is restored to its previous state.
+ */
+#define RKLogSilenceComponentWhileExecutingBlock(component, _block) \
+ RKLogToComponentWithLevelWhileExecutingBlock(component, RKLogLevelOff, _block)
/**
Temporarily changes the logging level for the configured RKLogComponent and executes the block. Any logging
@@ -149,7 +155,7 @@ lcl_configure_by_name("App", level);
/**
- Temporarily turns off logging for the execution of the block.
+ Temporarily turns off logging for current logging component during execution of the block.
After the block has finished execution, the logging level is restored to its previous state.
*/
#define RKLogSilenceWhileExecutingBlock(_block) \
@@ -77,20 +77,32 @@ - (id)objectFromFactory:(NSString *)factoryName
- (void)defineDefaultFactories
{
[self defineFactory:RKTestFactoryDefaultNamesClient withBlock:^id {
- RKClient *client = [RKClient clientWithBaseURL:self.baseURL];
- client.requestQueue.suspended = NO;
- [client.reachabilityObserver getFlags];
+ __block RKClient *client;
+
+ RKLogSilenceComponentWhileExecutingBlock(lcl_cRestKitNetworkReachability, ^{
+ RKLogSilenceComponentWhileExecutingBlock(lcl_cRestKitSupport, ^{
+ client = [RKClient clientWithBaseURL:self.baseURL];
+ client.requestQueue.suspended = NO;
+ [client.reachabilityObserver getFlags];
+ });
+ });
return client;
}];
[self defineFactory:RKTestFactoryDefaultNamesObjectManager withBlock:^id {
- RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:self.baseURL];
- RKObjectMappingProvider *mappingProvider = [self objectFromFactory:RKTestFactoryDefaultNamesMappingProvider];
- objectManager.mappingProvider = mappingProvider;
-
- // Force reachability determination
- [objectManager.client.reachabilityObserver getFlags];
+ __block RKObjectManager *objectManager;
+
+ RKLogSilenceComponentWhileExecutingBlock(lcl_cRestKitNetworkReachability, ^{
+ RKLogSilenceComponentWhileExecutingBlock(lcl_cRestKitSupport, ^{
+ objectManager = [RKObjectManager managerWithBaseURL:self.baseURL];
+ RKObjectMappingProvider *mappingProvider = [self objectFromFactory:RKTestFactoryDefaultNamesMappingProvider];
+ objectManager.mappingProvider = mappingProvider;
+
+ // Force reachability determination
+ [objectManager.client.reachabilityObserver getFlags];
+ });
+ });
return objectManager;
}];
@@ -194,7 +206,12 @@ + (void)setUp
{
[RKObjectManager setDefaultMappingQueue:dispatch_queue_create("org.restkit.ObjectMapping", DISPATCH_QUEUE_SERIAL)];
[RKObjectMapping setDefaultDateFormatters:nil];
- [RKManagedObjectStore deleteStoreInApplicationDataDirectoryWithFilename:RKTestFactoryDefaultStoreFilename];
+
+ // Delete the store if it exists
+ NSString *path = [[RKDirectory applicationDataDirectory] stringByAppendingPathComponent:RKTestFactoryDefaultStoreFilename];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
+ [RKManagedObjectStore deleteStoreInApplicationDataDirectoryWithFilename:RKTestFactoryDefaultStoreFilename];
+ }
if ([self respondsToSelector:@selector(didSetUp)]) {
[self didSetUp];
@@ -218,7 +235,7 @@ + (void)clearCacheDirectory
NSString* cachePath = [RKDirectory cachesDirectory];
BOOL success = [[NSFileManager defaultManager] removeItemAtPath:cachePath error:&error];
if (success) {
- RKLogInfo(@"Cleared cache directory...");
+ RKLogDebug(@"Cleared cache directory...");
success = [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:YES attributes:nil error:&error];
if (!success) {
RKLogError(@"Failed creation of cache path '%@': %@", cachePath, [error localizedDescription]);

0 comments on commit 680ca66

Please sign in to comment.