|
|
|
@ -20,8 +20,8 @@ |
|
|
|
|
|
|
|
|
|
#import "../../GRPCClient/GRPCCallOptions.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCChannel.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCChannelPool.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCChannelPool+Test.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCChannelPool.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCCompletionQueue.h" |
|
|
|
|
#import "../../GRPCClient/private/GRPCWrappedCall.h" |
|
|
|
|
|
|
|
|
@ -40,13 +40,12 @@ static NSString *kDummyPath = @"/dummy/path"; |
|
|
|
|
|
|
|
|
|
- (void)testPooledChannelCreatingChannel { |
|
|
|
|
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; |
|
|
|
|
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCChannelConfiguration *config = |
|
|
|
|
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options]; |
|
|
|
|
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config]; |
|
|
|
|
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; |
|
|
|
|
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCWrappedCall *wrappedCall = |
|
|
|
|
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertNotNil(channel.wrappedChannel); |
|
|
|
|
(void)wrappedCall; |
|
|
|
|
} |
|
|
|
@ -54,26 +53,22 @@ static NSString *kDummyPath = @"/dummy/path"; |
|
|
|
|
- (void)testTimedDestroyChannel { |
|
|
|
|
const NSTimeInterval kDestroyDelay = 1.0; |
|
|
|
|
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; |
|
|
|
|
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config |
|
|
|
|
destroyDelay:kDestroyDelay]; |
|
|
|
|
GRPCChannelConfiguration *config = |
|
|
|
|
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options]; |
|
|
|
|
GRPCPooledChannel *channel = |
|
|
|
|
[[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay]; |
|
|
|
|
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; |
|
|
|
|
GRPCWrappedCall *wrappedCall; |
|
|
|
|
GRPCChannel *wrappedChannel; |
|
|
|
|
@autoreleasepool { |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertNotNil(channel.wrappedChannel); |
|
|
|
|
|
|
|
|
|
// Unref and ref channel immediately; expect using the same raw channel. |
|
|
|
|
wrappedChannel = channel.wrappedChannel; |
|
|
|
|
|
|
|
|
|
wrappedCall = nil; |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertEqual(channel.wrappedChannel, wrappedChannel); |
|
|
|
|
|
|
|
|
|
// Unref and ref channel after destroy delay; expect a new raw channel. |
|
|
|
@ -81,23 +76,20 @@ static NSString *kDummyPath = @"/dummy/path"; |
|
|
|
|
} |
|
|
|
|
sleep(kDestroyDelay + 1); |
|
|
|
|
XCTAssertNil(channel.wrappedChannel); |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertNotEqual(channel.wrappedChannel, wrappedChannel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testDisconnect { |
|
|
|
|
const NSTimeInterval kDestroyDelay = 1.0; |
|
|
|
|
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; |
|
|
|
|
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config |
|
|
|
|
destroyDelay:kDestroyDelay]; |
|
|
|
|
GRPCChannelConfiguration *config = |
|
|
|
|
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options]; |
|
|
|
|
GRPCPooledChannel *channel = |
|
|
|
|
[[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay]; |
|
|
|
|
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; |
|
|
|
|
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCWrappedCall *wrappedCall = |
|
|
|
|
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertNotNil(channel.wrappedChannel); |
|
|
|
|
|
|
|
|
|
// Disconnect; expect wrapped channel to be dropped |
|
|
|
@ -106,9 +98,8 @@ static NSString *kDummyPath = @"/dummy/path"; |
|
|
|
|
|
|
|
|
|
// Create a new call and unref the old call; confirm that destroy of the old call does not make |
|
|
|
|
// the channel disconnect, even after the destroy delay. |
|
|
|
|
GRPCWrappedCall *wrappedCall2 = [channel wrappedCallWithPath:kDummyPath |
|
|
|
|
completionQueue:cq |
|
|
|
|
callOptions:options]; |
|
|
|
|
GRPCWrappedCall *wrappedCall2 = |
|
|
|
|
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options]; |
|
|
|
|
XCTAssertNotNil(channel.wrappedChannel); |
|
|
|
|
GRPCChannel *wrappedChannel = channel.wrappedChannel; |
|
|
|
|
wrappedCall = nil; |
|
|
|
|