Permalink
Browse files

Added some logging for server time diffs

  • Loading branch information...
1 parent 4a2da5b commit 8c2ff817a2cf93cf6fc4f79e241df80c43c64afe @msv msv committed May 31, 2012
View
@@ -401,7 +401,21 @@ - (void)connectionDidFinishLoading:(NSURLConnection*)connection
SMLog(@"RESPONSE CODE %d", statusCode);
if ([mConnectionData length] > 0) {
textResult = [[[NSString alloc] initWithData:mConnectionData encoding:NSUTF8StringEncoding] autorelease];
- SMLog(@"RESPONSE BODY %@", textResult);
+
+
+#if DEBUG
+
+ if ([textResult length] > 2000)
+ {
+ SMLog(@"textResult was greater than 2000, truncating for logging purposes");
+ SMLog(@"RESPONSE BODY %@", [textResult substringToIndex:2000]);
+ }
+ else {
+ SMLog(@"RESPONSE BODY %@", textResult);
+ }
+
+#endif
+
}
[session recordServerTimeDiffFromHeader:[[mHttpResponse allHeaderFields] valueForKey:@"Date"]];
@@ -173,7 +173,7 @@ - (void)setup{
pushURL = [[NSString stringWithFormat:@"http://push.%@.%@", _subDomain, _domain] retain];
secureURL = [[NSString stringWithFormat:@"https://%@", url] retain];
regularURL = [[NSString stringWithFormat:@"http://%@", url] retain];
- _serverTimeDiff = [[NSUserDefaults standardUserDefaults] integerForKey:serverTimeDiffKey];
+ _serverTimeDiff = [[NSUserDefaults standardUserDefaults] doubleForKey:serverTimeDiffKey];
_nextTimeCheck = [[NSDate date] retain];
}
@@ -217,18 +217,22 @@ - (NSString *)userAgentString {
}
- (NSDate *)getServerTime {
+ SMLog(@"Applying a time difference of %f", _serverTimeDiff);
return [NSDate dateWithTimeIntervalSinceNow:_serverTimeDiff];
}
-(void)recordServerTimeDiffFromHeader:(NSString*)header {
if (header != nil) {
+
NSDateFormatter *rfcFormatter = [[NSDateFormatter alloc] init];
[rfcFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];
NSDate *serverTime = [rfcFormatter dateFromString:header];
_serverTimeDiff = [serverTime timeIntervalSinceDate:[NSDate date]];
+ SMLog(@"Server time is %@ and diff is %f", serverTime, _serverTimeDiff);
if([[NSDate date] earlierDate:_nextTimeCheck] == _nextTimeCheck) {
// Save the date to persistent storage every ten minutes
- [[NSUserDefaults standardUserDefaults] setInteger:_serverTimeDiff forKey:serverTimeDiffKey];
+ [[NSUserDefaults standardUserDefaults] setDouble:_serverTimeDiff forKey:serverTimeDiffKey];
+ SMLog(@"Server time diff after saving to NSUSerDefaults is %f", [[NSUserDefaults standardUserDefaults] doubleForKey:serverTimeDiffKey]);
NSDate *newDate = [[NSDate dateWithTimeIntervalSinceNow:10 * 60] retain];
[_nextTimeCheck release];
_nextTimeCheck = newDate;
@@ -747,7 +747,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = StackMobiOS_Prefix.pch;
- GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=0";
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
@@ -784,7 +784,7 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = StackMobiOS_Prefix.pch;
- GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
@@ -873,6 +873,7 @@
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREFIX_HEADER = StackMobiOS_Prefix.pch;
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
INFOPLIST_FILE = "Tests-Info.plist";
OTHER_LDFLAGS = (
"-framework",
View
@@ -109,7 +109,6 @@ - (void) testIsNotNullGet {
[request sendRequest];
//we need to loop until the request comes back, its just a test its OK
[StackMobTestUtils runRunLoop:[NSRunLoop currentRunLoop] untilRequestFinished:request];
-
STAssertTrue([[request result] isKindOfClass:[NSArray class]], @"Did not get a valid GET result");
for (NSDictionary *d in [request result]) {
@@ -353,7 +352,6 @@ -(StackMobRequest *) ensureUser:(NSString *)username withEmail:(NSString *)email
- (void) testLoginLogout {
STAssertFalse([[StackMob stackmob] isLoggedIn], @"Shouldn't be logged in yet");
- STAssertFalse([[StackMob stackmob] isLoggedOut], @"Shouldn't be logged out yet");
STAssertNil([[StackMob stackmob] loggedInUser], @"Shouldn't be logged in yet");
STAssertFalse([[StackMob stackmob] isUserLoggedIn:@"Azure"], @"Shouldn't be logged in yet");
NSMutableDictionary *loginRequest = [[NSMutableDictionary alloc] init];
@@ -375,7 +373,6 @@ - (void) testLoginLogout {
}
}];
STAssertFalse([[StackMob stackmob] isLoggedIn], @"Shouldn't be logged in yet");
- STAssertFalse([[StackMob stackmob] isLoggedOut], @"Shouldn't be logged out yet");
STAssertNil([[StackMob stackmob] loggedInUser], @"Shouldn't be logged in yet");
STAssertFalse([[StackMob stackmob] isUserLoggedIn:@"Azure"], @"Shouldn't be logged in yet");
[StackMobTestUtils runRunLoop:[NSRunLoop currentRunLoop] untilRequestFinished:request];
@@ -49,7 +49,7 @@ - (void)testNSMutableDictionaryAddition
//we need to loop until the request comes back, its just a test its OK
result = [StackMobTestUtils runDefaultRunLoopAndGetDictionaryResultFromRequest:updateRequest];
- NSLog(@"testNSMutableDictionaryAddition result was: %@", result);
+ SMLog(@"testNSMutableDictionaryAddition result was: %@", result);
info = (NSDictionary *)result;
int updateValue = [[info objectForKey:FIELD_TO_UPDATE] intValue];
STAssertTrue(updateValue == (originalValue + 1), nil);
@@ -94,7 +94,7 @@ - (void)testNSDictionaryAddition
//we need to loop until the request comes back, its just a test its OK
result = [StackMobTestUtils runDefaultRunLoopAndGetDictionaryResultFromRequest:updateRequest];
- NSLog(@"testNSMutableDictionaryAddition result was: %@", result);
+ SMLog(@"testNSMutableDictionaryAddition result was: %@", result);
info = (NSDictionary *)result;
int updateValue = [[info objectForKey:FIELD_TO_UPDATE] intValue];
STAssertTrue(updateValue == (originalValue + 1), nil);
@@ -137,7 +137,7 @@ - (void)testStackMobUpdateCounterMethod
//we need to loop until the request comes back, its just a test its OK
result = [StackMobTestUtils runDefaultRunLoopAndGetDictionaryResultFromRequest:updateRequest];
- NSLog(@"testNSMutableDictionaryAddition result was: %@", result);
+ SMLog(@"testNSMutableDictionaryAddition result was: %@", result);
info = (NSDictionary *)result;
int updateValue = [[info objectForKey:FIELD_TO_UPDATE] intValue];
STAssertTrue(updateValue == (originalValue + 1), nil);

1 comment on commit 8c2ff81

Contributor

drapp commented on 8c2ff81 May 31, 2012

Looks good. maybe this will fix the guy's problem?

Please sign in to comment.