aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests/ChannelTests/ChannelTests.m
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-11-08 22:01:10 -0800
committerGravatar Muxi Yan <mxyan@google.com>2018-11-08 22:01:10 -0800
commit37dbad80d5254f9bf17076d12b22b7a081e6e9dc (patch)
tree367a86331b789917812b15ec4dde636b32560023 /src/objective-c/tests/ChannelTests/ChannelTests.m
parentd72d5b2c8eaa8a434a7db4624fe6a45bc0d6bde4 (diff)
Refactor channel pool
Diffstat (limited to 'src/objective-c/tests/ChannelTests/ChannelTests.m')
-rw-r--r--src/objective-c/tests/ChannelTests/ChannelTests.m97
1 files changed, 43 insertions, 54 deletions
diff --git a/src/objective-c/tests/ChannelTests/ChannelTests.m b/src/objective-c/tests/ChannelTests/ChannelTests.m
index 64c3356b13..27e76d4179 100644
--- a/src/objective-c/tests/ChannelTests/ChannelTests.m
+++ b/src/objective-c/tests/ChannelTests/ChannelTests.m
@@ -20,6 +20,7 @@
#import "../../GRPCClient/GRPCCallOptions.h"
#import "../../GRPCClient/private/GRPCChannel.h"
+#import "../../GRPCClient/private/GRPCCompletionQueue.h"
@interface ChannelTests : XCTestCase
@@ -31,63 +32,51 @@
grpc_init();
}
-- (void)testSameConfiguration {
- NSString *host = @"grpc-test.sandbox.googleapis.com";
- GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
- options.userAgentPrefix = @"TestUAPrefix";
- NSMutableDictionary *args = [NSMutableDictionary new];
- args[@"abc"] = @"xyz";
- options.additionalChannelArgs = [args copy];
- GRPCChannel *channel1 = [GRPCChannel channelWithHost:host callOptions:options];
- GRPCChannel *channel2 = [GRPCChannel channelWithHost:host callOptions:options];
- XCTAssertEqual(channel1, channel2);
- GRPCMutableCallOptions *options2 = [options mutableCopy];
- options2.additionalChannelArgs = [args copy];
- GRPCChannel *channel3 = [GRPCChannel channelWithHost:host callOptions:options2];
- XCTAssertEqual(channel1, channel3);
-}
+- (void)testTimedDisconnection {
+ NSString * const kHost = @"grpc-test.sandbox.googleapis.com";
+ const NSTimeInterval kDestroyDelay = 1;
+ GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
+ GRPCChannelConfiguration *configuration = [[GRPCChannelConfiguration alloc] initWithHost:kHost callOptions:options];
+ GRPCChannel *channel = [[GRPCChannel alloc] initWithChannelConfiguration:configuration
+ destroyDelay:kDestroyDelay];
+ BOOL disconnected;
+ grpc_call *call = [channel unmanagedCallWithPath:@"dummy.path"
+ completionQueue:[GRPCCompletionQueue completionQueue]
+ callOptions:options
+ disconnected:&disconnected];
+ XCTAssertFalse(disconnected);
+ grpc_call_unref(call);
+ [channel unref];
+ XCTAssertFalse(channel.disconnected, @"Channel is pre-maturely disconnected.");
+ sleep(kDestroyDelay + 1);
+ XCTAssertTrue(channel.disconnected, @"Channel is not disconnected after delay.");
-- (void)testDifferentHost {
- NSString *host1 = @"grpc-test.sandbox.googleapis.com";
- NSString *host2 = @"grpc-test2.sandbox.googleapis.com";
- NSString *host3 = @"http://grpc-test.sandbox.googleapis.com";
- NSString *host4 = @"dns://grpc-test.sandbox.googleapis.com";
- NSString *host5 = @"grpc-test.sandbox.googleapis.com:80";
- GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
- options.userAgentPrefix = @"TestUAPrefix";
- NSMutableDictionary *args = [NSMutableDictionary new];
- args[@"abc"] = @"xyz";
- options.additionalChannelArgs = [args copy];
- GRPCChannel *channel1 = [GRPCChannel channelWithHost:host1 callOptions:options];
- GRPCChannel *channel2 = [GRPCChannel channelWithHost:host2 callOptions:options];
- GRPCChannel *channel3 = [GRPCChannel channelWithHost:host3 callOptions:options];
- GRPCChannel *channel4 = [GRPCChannel channelWithHost:host4 callOptions:options];
- GRPCChannel *channel5 = [GRPCChannel channelWithHost:host5 callOptions:options];
- XCTAssertNotEqual(channel1, channel2);
- XCTAssertNotEqual(channel1, channel3);
- XCTAssertNotEqual(channel1, channel4);
- XCTAssertNotEqual(channel1, channel5);
+ // Check another call creation returns null and indicates disconnected.
+ call = [channel unmanagedCallWithPath:@"dummy.path"
+ completionQueue:[GRPCCompletionQueue completionQueue]
+ callOptions:options
+ disconnected:&disconnected];
+ XCTAssert(call == NULL);
+ XCTAssertTrue(disconnected);
}
-- (void)testDifferentChannelParameters {
- NSString *host = @"grpc-test.sandbox.googleapis.com";
- GRPCMutableCallOptions *options1 = [[GRPCMutableCallOptions alloc] init];
- options1.transportType = GRPCTransportTypeChttp2BoringSSL;
- NSMutableDictionary *args = [NSMutableDictionary new];
- args[@"abc"] = @"xyz";
- options1.additionalChannelArgs = [args copy];
- GRPCMutableCallOptions *options2 = [[GRPCMutableCallOptions alloc] init];
- options2.transportType = GRPCTransportTypeInsecure;
- options2.additionalChannelArgs = [args copy];
- GRPCMutableCallOptions *options3 = [[GRPCMutableCallOptions alloc] init];
- options3.transportType = GRPCTransportTypeChttp2BoringSSL;
- args[@"def"] = @"uvw";
- options3.additionalChannelArgs = [args copy];
- GRPCChannel *channel1 = [GRPCChannel channelWithHost:host callOptions:options1];
- GRPCChannel *channel2 = [GRPCChannel channelWithHost:host callOptions:options2];
- GRPCChannel *channel3 = [GRPCChannel channelWithHost:host callOptions:options3];
- XCTAssertNotEqual(channel1, channel2);
- XCTAssertNotEqual(channel1, channel3);
+- (void)testForceDisconnection {
+ NSString * const kHost = @"grpc-test.sandbox.googleapis.com";
+ const NSTimeInterval kDestroyDelay = 1;
+ GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
+ GRPCChannelConfiguration *configuration = [[GRPCChannelConfiguration alloc] initWithHost:kHost callOptions:options];
+ GRPCChannel *channel = [[GRPCChannel alloc] initWithChannelConfiguration:configuration
+ destroyDelay:kDestroyDelay];
+ grpc_call *call = [channel unmanagedCallWithPath:@"dummy.path"
+ completionQueue:[GRPCCompletionQueue completionQueue]
+ callOptions:options
+ disconnected:nil];
+ grpc_call_unref(call);
+ [channel disconnect];
+ XCTAssertTrue(channel.disconnected, @"Channel is not disconnected.");
+
+ // Test calling another unref here will not crash
+ [channel unref];
}
@end