From 068679eaaf6176cde7ff80e1ac643c7554342f16 Mon Sep 17 00:00:00 2001 From: Alex Billingsley Date: Fri, 18 Mar 2016 14:38:55 -0400 Subject: [PATCH 1/5] Enable Code Coverage --- .../xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme | 3 ++- .../xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme index b1053ddb..626fc679 100644 --- a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme +++ b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme index 767bf913..5f51ca77 100644 --- a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme +++ b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> From 73bcbfd5577eaf5db497ff1526de663a51ed9c55 Mon Sep 17 00:00:00 2001 From: Alex Billingsley Date: Wed, 23 Mar 2016 18:04:47 -0400 Subject: [PATCH 2/5] Transition connection to disconnected on negotiate or start transport failure #254 --- SignalR.Client/SRConnection.m | 4 ++-- Tests/Tests/SRConnectionTests.m | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/SignalR.Client/SRConnection.m b/SignalR.Client/SRConnection.m index 01d98072..fcd23734 100644 --- a/SignalR.Client/SRConnection.m +++ b/SignalR.Client/SRConnection.m @@ -153,7 +153,7 @@ - (void)negotiate:(id)transport { } else { SRLogConnectionError(@"negotiation failed %@", error); [strongSelf didReceiveError:error]; - [strongSelf didClose]; + [strongSelf stopButDoNotCallServer]; } }]; } @@ -182,7 +182,7 @@ - (void)startTransport { } else { SRLogConnectionError(@"start transport failed %@",error); [strongSelf didReceiveError:error]; - [strongSelf didClose]; + [strongSelf stopButDoNotCallServer]; } }]; } diff --git a/Tests/Tests/SRConnectionTests.m b/Tests/Tests/SRConnectionTests.m index 45ae95b8..8f312e67 100644 --- a/Tests/Tests/SRConnectionTests.m +++ b/Tests/Tests/SRConnectionTests.m @@ -116,4 +116,44 @@ - (void) testTransportNegotiateCausesClosed }]; } +- (void)testConnectionCanRestartAfterNegotiateError { + id failingTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport negotiateForMockTransport:failingTransport statusCode:@400 error:[NSError errorWithDomain:@"UNIT TEST" code:NSURLErrorTimedOut userInfo:nil]]; + + id successTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [[successTransport expect] negotiate:[OCMArg any] connectionData:[OCMArg any] completionHandler:[OCMArg any]]; + + SRConnection* connection = [[SRConnection alloc] initWithURLString:@"http://localhost:0000"]; + [connection start: failingTransport]; + XCTAssertEqual(connection.state, disconnected); + [connection start: successTransport]; + XCTAssertEqual(connection.state, connecting); + [successTransport verify]; + +} + +- (void)testConnectionCanRestartAfterStartError { + id failingTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport startForMockTransport:failingTransport statusCode:@400 error:[[NSError alloc]initWithDomain:@"Expected" code:42 userInfo:nil]]; + id json = @{ + @"ConnectionId": @"10101", + @"ConnectionToken": @"10101010101", + @"DisconnectTimeout": @30, + @"ProtocolVersion": @"1.3.0.0" + }; + [SRMockClientTransport negotiateForMockTransport:failingTransport statusCode:@200 json:json]; + + id successTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport negotiateForMockTransport:successTransport statusCode:@200 json:json]; + [[successTransport expect] start:[OCMArg any] connectionData:[OCMArg any] completionHandler:[OCMArg any]]; + + SRConnection* connection = [[SRConnection alloc] initWithURLString:@"http://localhost:0000"]; + [connection start: failingTransport]; + XCTAssertEqual(connection.state, disconnected); + [connection start: successTransport]; + XCTAssertEqual(connection.state, connecting); + [successTransport verify]; + +} + @end From cc20dfee63f88fd49557a22d5f3c5f2314362218 Mon Sep 17 00:00:00 2001 From: Richard Groves Date: Mon, 20 Jun 2016 14:51:46 +0100 Subject: [PATCH 3/5] Replacing connectionWithURL: with connectionWithURLString: The method to create a connection from a URL string is named [SRConnection connectionWithURLString:] - fixing the example code to use it. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a9bef351..21f595e1 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ public class MyConnection : PersistentConnection #import "SignalR.h" //Client -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite/echo"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite/echo"]; // Register for connection lifecycle events [connection setStarted:^{ @@ -131,7 +131,7 @@ public class Chat : Hub #import "SignalR.h" // Connect to the service -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; // Create a proxy to the chat service SRHubProxy *chat = [hubConnection createHubProxy:@"chat"]; [chat on:@"addMessage" perform:self selector:@selector(addMessage:)]; @@ -176,7 +176,7 @@ id qs = @{ @"param1": @1, @"param2": @"another" }; -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite" queryString:qs]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite" queryString:qs]; ``` #### Hub Connections @@ -185,7 +185,7 @@ id qs = @{ @"param1": @1, @"param2": @"another" }; -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite" queryString:qs]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite" queryString:qs]; ``` ### Customizing Request Headers @@ -196,11 +196,11 @@ id headers = @{ @"param1": @1, @"param2": @"another" }; -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite"]; [connection setHeaders:headers]; //Alternative Usage -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite"]; [connection addValue:@"1" forHTTPHeaderField:@"param1"]; [connection addValue:@"another" forHTTPHeaderField:@"param2"]; ``` @@ -211,11 +211,11 @@ id headers = @{ @"param1": @1, @"param2": @"another" }; -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; [hubConnection setHeaders:headers]; //Alternative Usage -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; [hubConnection addValue:@"1" forHTTPHeaderField:@"param1"]; [hubConnection addValue:@"another" forHTTPHeaderField:@"param2"]; ``` From cece1ea22c4e1565d980eb3364fdfe21558db6db Mon Sep 17 00:00:00 2001 From: Richard Groves Date: Mon, 20 Jun 2016 17:38:28 +0100 Subject: [PATCH 4/5] Fixing typo that broke verbose logging Base verbose log method had a typo in its name which meant it failed to compile ":5: Implicit declaration of function 'SRLogVerboase' is invalid in C99" when one of the verbose methods was used. --- SignalR.Client/SRLog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalR.Client/SRLog.h b/SignalR.Client/SRLog.h index cd9c3ade..b9b6da84 100644 --- a/SignalR.Client/SRLog.h +++ b/SignalR.Client/SRLog.h @@ -50,7 +50,7 @@ static const int ddLogLevel = LOG_LEVEL_VERBOSE; #define SRLogPrefixedWarn(type, frmt, ...) SRLogWarn(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogPrefixedInfo(type, frmt, ...) SRLogInfo(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogPrefixedDebug(type, frmt, ...) SRLogDebug(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); -#define SRLogPrefixedVerbose(type, frmt, ...) SRLogVerboase(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); +#define SRLogPrefixedVerbose(type, frmt, ...) SRLogVerbose(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogConnectionError(frmt, ...) SRLogPrefixedError(@"CONNECTION", frmt, ##__VA_ARGS__); #define SRLogConnectionWarn(frmt, ...) SRLogPrefixedWarn(@"CONNECTION", frmt, ##__VA_ARGS__); From 34e38401ce5104a7174363e75643e8ec26414e3c Mon Sep 17 00:00:00 2001 From: Richard Groves Date: Tue, 21 Jun 2016 10:26:40 +0100 Subject: [PATCH 5/5] Fixing typos in comments --- SignalR.Client/Hubs/SRHubResult.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SignalR.Client/Hubs/SRHubResult.h b/SignalR.Client/Hubs/SRHubResult.h index 996962a1..2ff67e30 100644 --- a/SignalR.Client/Hubs/SRHubResult.h +++ b/SignalR.Client/Hubs/SRHubResult.h @@ -42,7 +42,7 @@ @property (assign, nonatomic, readwrite, getter = isHubException) BOOL hubException; /** - * An `NSString` represnting an error received from the server + * An `NSString` representing an error received from the server */ @property (strong, nonatomic, readwrite) NSString *error; @@ -52,7 +52,7 @@ @property (strong, nonatomic, readwrite) id errorData; /** - * An `NSDictionary` represnting a server state object + * An `NSDictionary` representing a server state object */ @property (strong, nonatomic, readwrite) NSDictionary *state;