3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #import <XCTest/XCTest.h>
21 #import "../../GRPCClient/private/GRPCChannel.h"
22 #import "../../GRPCClient/private/GRPCChannelPool+Test.h"
23 #import "../../GRPCClient/private/GRPCCompletionQueue.h"
25 #define TEST_TIMEOUT 32
27 static NSString *kDummyHost = @"dummy.host";
28 static NSString *kDummyHost2 = @"dummy.host.2";
29 static NSString *kDummyPath = @"/dummy/path";
31 @interface ChannelPoolTest : XCTestCase
35 @implementation ChannelPoolTest
41 - (void)testCreateAndCacheChannel {
42 GRPCChannelPool *pool = [[GRPCChannelPool alloc] initTestPool];
43 GRPCCallOptions *options1 = [[GRPCCallOptions alloc] init];
44 GRPCCallOptions *options2 = [options1 copy];
45 GRPCMutableCallOptions *options3 = [options1 mutableCopy];
46 options3.transportType = GRPCTransportTypeInsecure;
48 GRPCPooledChannel *channel1 = [pool channelWithHost:kDummyHost callOptions:options1];
49 GRPCPooledChannel *channel2 = [pool channelWithHost:kDummyHost callOptions:options2];
50 GRPCPooledChannel *channel3 = [pool channelWithHost:kDummyHost callOptions:options3];
51 GRPCPooledChannel *channel4 = [pool channelWithHost:kDummyHost2 callOptions:options1];
53 XCTAssertNotNil(channel1);
54 XCTAssertNotNil(channel2);
55 XCTAssertNotNil(channel3);
56 XCTAssertNotNil(channel4);
57 XCTAssertEqual(channel1, channel2);
58 XCTAssertNotEqual(channel1, channel3);
59 XCTAssertNotEqual(channel1, channel4);
60 XCTAssertNotEqual(channel3, channel4);