带阿里标识的版本
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
//
|
||||
// HttpdnsNWHTTPClient_StateMachineTests.m
|
||||
// AlicloudHttpDNSTests
|
||||
// TrustHttpDNSTests
|
||||
//
|
||||
// @author Created by Claude Code on 2025-11-01
|
||||
// Copyright © 2025 alibaba-inc.com. All rights reserved.
|
||||
// Copyright © 2025 trustapp.com. All rights reserved.
|
||||
//
|
||||
// 状态机测试 - 包含状态机与异常场景 (Q) 测试组
|
||||
// 测试总数:17 个(Q:17)
|
||||
// 状态机测试 - 包含状态机与异常场<EFBFBD><EFBFBD>?(Q) 测试<EFBFBD><EFBFBD>?
|
||||
// 测试总数<EFBFBD><EFBFBD>?7 个(Q:17<EFBFBD><EFBFBD>?
|
||||
//
|
||||
|
||||
#import "HttpdnsNWHTTPClientTestBase.h"
|
||||
@@ -17,18 +17,18 @@
|
||||
|
||||
@implementation HttpdnsNWHTTPClient_StateMachineTests
|
||||
|
||||
#pragma mark - Q. 状态机与异常场景测试
|
||||
#pragma mark - Q. 状态机与异常场景测<EFBFBD><EFBFBD>?
|
||||
|
||||
// Q1.1 池溢出时LRU移除策略验证
|
||||
- (void)testStateMachine_PoolOverflowLRU_RemovesOldestByLastUsedDate {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 需要并发创建5个连接(串行请求会复用)
|
||||
// 需要并发创<EFBFBD><EFBFBD>?个连接(串行请求会复用)
|
||||
NSMutableArray<XCTestExpectation *> *expectations = [NSMutableArray array];
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
// 并发发起5个请求
|
||||
// 并发发起5个请<EFBFBD><EFBFBD>?
|
||||
for (NSInteger i = 0; i < 5; i++) {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"Request %ld", (long)i]];
|
||||
[expectations addObject:expectation];
|
||||
@@ -42,15 +42,15 @@
|
||||
error:&error];
|
||||
[expectation fulfill];
|
||||
});
|
||||
[NSThread sleepForTimeInterval:0.05]; // 小间隔避免完全同时启动
|
||||
[NSThread sleepForTimeInterval:0.05]; // 小间隔避免完全同时启<EFBFBD><EFBFBD>?
|
||||
}
|
||||
|
||||
[self waitForExpectations:expectations timeout:20.0];
|
||||
|
||||
// 等待所有连接归还
|
||||
// 等待所有连接归<EFBFBD><EFBFBD>?
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 验证:池大小 ≤ 4(LRU移除溢出部分)
|
||||
// 验证:池大小 <EFBFBD><EFBFBD>?4(LRU移除溢出部分<EFBFBD><EFBFBD>?
|
||||
NSUInteger poolCount = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertLessThanOrEqual(poolCount, 4,
|
||||
@"Pool should enforce max 4 connections (LRU)");
|
||||
@@ -65,7 +65,7 @@
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 快速连续发起10个请求(测试连接归还的幂等性)
|
||||
// 快速连续发<EFBFBD><EFBFBD>?0个请求(测试连接归还的幂等性)
|
||||
for (NSInteger i = 0; i < 10; i++) {
|
||||
NSError *error = nil;
|
||||
HttpdnsNWHTTPClientResponse *response = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
@@ -78,12 +78,12 @@
|
||||
// 等待连接归还
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 验证:池中最多1个连接(因为串行请求复用同一连接)
|
||||
// 验证:池中最<EFBFBD><EFBFBD>?个连接(因为串行请求复用同一连接<EFBFBD><EFBFBD>?
|
||||
NSUInteger poolCount = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertLessThanOrEqual(poolCount, 1,
|
||||
@"Pool should have at most 1 connection (rapid sequential reuse)");
|
||||
|
||||
// 验证:创建次数应该是1(所有请求复用同一连接)
|
||||
// 验证:创建次数应该是1(所有请求复用同一连接<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual(self.client.connectionCreationCount, 1,
|
||||
@"Should create only 1 connection for sequential requests");
|
||||
}
|
||||
@@ -94,7 +94,7 @@
|
||||
NSString *poolKey11080 = @"127.0.0.1:11080:tcp";
|
||||
NSString *poolKey11443 = @"127.0.0.1:11443:tls";
|
||||
|
||||
// 向端口11080发起请求
|
||||
// 向端<EFBFBD><EFBFBD>?1080发起请求
|
||||
NSError *error1 = nil;
|
||||
HttpdnsNWHTTPClientResponse *response1 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"Port11080"
|
||||
@@ -102,7 +102,7 @@
|
||||
error:&error1];
|
||||
XCTAssertNotNil(response1);
|
||||
|
||||
// 向端口11443发起请求
|
||||
// 向端<EFBFBD><EFBFBD>?1443发起请求
|
||||
NSError *error2 = nil;
|
||||
HttpdnsNWHTTPClientResponse *response2 = [self.client performRequestWithURLString:@"https://127.0.0.1:11443/get"
|
||||
userAgent:@"Port11443"
|
||||
@@ -113,7 +113,7 @@
|
||||
// 等待连接归还
|
||||
[NSThread sleepForTimeInterval:0.5];
|
||||
|
||||
// 验证:两个池各自有1个连接
|
||||
// 验证:两个池各自<EFBFBD><EFBFBD>?个连<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual([self.client connectionPoolCountForKey:poolKey11080], 1,
|
||||
@"Port 11080 pool should have 1 connection");
|
||||
XCTAssertEqual([self.client connectionPoolCountForKey:poolKey11443], 1,
|
||||
@@ -128,7 +128,7 @@
|
||||
- (void)testInvariant_PoolSize_NeverExceedsLimit {
|
||||
[self.client resetPoolStatistics];
|
||||
|
||||
// 快速连续发起20个请求到同一端点
|
||||
// 快速连续发<EFBFBD><EFBFBD>?0个请求到同一端点
|
||||
for (NSInteger i = 0; i < 20; i++) {
|
||||
NSError *error = nil;
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
@@ -137,7 +137,7 @@
|
||||
error:&error];
|
||||
}
|
||||
|
||||
// 等待所有连接归还
|
||||
// 等待所有连接归<EFBFBD><EFBFBD>?
|
||||
[NSThread sleepForTimeInterval:1.5];
|
||||
|
||||
// 验证:每个池的大小不超过4
|
||||
@@ -149,7 +149,7 @@
|
||||
key, (unsigned long)poolCount);
|
||||
}
|
||||
|
||||
// 验证:总连接数也不超过4(因为只有一个池)
|
||||
// 验证:总连接数也不超过4(因为只有一个池<EFBFBD><EFBFBD>?
|
||||
XCTAssertLessThanOrEqual([self.client totalConnectionCount], 4,
|
||||
@"Total connections should not exceed 4");
|
||||
}
|
||||
@@ -162,7 +162,7 @@
|
||||
NSMutableArray<XCTestExpectation *> *expectations = [NSMutableArray array];
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
// 并发发起15个请求(可能复用连接)
|
||||
// 并发发起15个请求(可能复用连接<EFBFBD><EFBFBD>?
|
||||
for (NSInteger i = 0; i < 15; i++) {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"Request %ld", (long)i]];
|
||||
[expectations addObject:expectation];
|
||||
@@ -182,17 +182,17 @@
|
||||
// 等待连接归还
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 验证:池大小 ≤ 4(不变式)
|
||||
// 验证:池大小 <EFBFBD><EFBFBD>?4(不变式<EFBFBD><EFBFBD>?
|
||||
NSUInteger poolCount = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertLessThanOrEqual(poolCount, 4,
|
||||
@"Pool should not have duplicates (max 4 connections)");
|
||||
|
||||
// 验证:创建的连接数合理(≤15,因为可能有复用)
|
||||
// 验证:创建的连接数合理(<EFBFBD><EFBFBD>?5,因为可能有复用<EFBFBD><EFBFBD>?
|
||||
XCTAssertLessThanOrEqual(self.client.connectionCreationCount, 15,
|
||||
@"Should not create excessive connections");
|
||||
}
|
||||
|
||||
// Q4.1 边界条件:恰好30秒后连接过期
|
||||
// Q4.1 边界条件:恰<EFBFBD><EFBFBD>?0秒后连接过期
|
||||
- (void)testBoundary_Exactly30Seconds_ConnectionExpired {
|
||||
if (getenv("SKIP_SLOW_TESTS")) {
|
||||
return;
|
||||
@@ -200,7 +200,7 @@
|
||||
|
||||
[self.client resetPoolStatistics];
|
||||
|
||||
// 第一个请求
|
||||
// 第一个请<EFBFBD><EFBFBD>?
|
||||
NSError *error1 = nil;
|
||||
HttpdnsNWHTTPClientResponse *response1 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"InitialRequest"
|
||||
@@ -211,7 +211,7 @@
|
||||
// 等待恰好30.5秒(超过30秒过期时间)
|
||||
[NSThread sleepForTimeInterval:30.5];
|
||||
|
||||
// 第二个请求:应该创建新连接(旧连接已过期)
|
||||
// 第二个请求:应该创建新连接(旧连接已过期<EFBFBD><EFBFBD>?
|
||||
NSError *error2 = nil;
|
||||
HttpdnsNWHTTPClientResponse *response2 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"AfterExpiry"
|
||||
@@ -219,18 +219,18 @@
|
||||
error:&error2];
|
||||
XCTAssertNotNil(response2);
|
||||
|
||||
// 验证:创建了2个连接(旧连接过期,无法复用)
|
||||
// 验证:创建了2个连接(旧连接过期,无法复用<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual(self.client.connectionCreationCount, 2,
|
||||
@"Should create 2 connections (first expired after 30s)");
|
||||
XCTAssertEqual(self.client.connectionReuseCount, 0,
|
||||
@"Should not reuse expired connection");
|
||||
}
|
||||
|
||||
// Q4.2 边界条件:29秒内连接未过期
|
||||
// Q4.2 边界条件<EFBFBD><EFBFBD>?9秒内连接未过<EFBFBD><EFBFBD>?
|
||||
- (void)testBoundary_Under30Seconds_ConnectionNotExpired {
|
||||
[self.client resetPoolStatistics];
|
||||
|
||||
// 第一个请求
|
||||
// 第一个请<EFBFBD><EFBFBD>?
|
||||
NSError *error1 = nil;
|
||||
HttpdnsNWHTTPClientResponse *response1 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"InitialRequest"
|
||||
@@ -249,19 +249,19 @@
|
||||
error:&error2];
|
||||
XCTAssertNotNil(response2);
|
||||
|
||||
// 验证:只创建了1个连接(复用了)
|
||||
// 验证:只创建<EFBFBD><EFBFBD>?个连接(复用了)
|
||||
XCTAssertEqual(self.client.connectionCreationCount, 1,
|
||||
@"Should create only 1 connection (reused within 30s)");
|
||||
XCTAssertEqual(self.client.connectionReuseCount, 1,
|
||||
@"Should reuse connection within 30s");
|
||||
}
|
||||
|
||||
// Q4.3 边界条件:恰好4个连接全部保留
|
||||
// Q4.3 边界条件:恰<EFBFBD><EFBFBD>?个连接全部保<EFBFBD><EFBFBD>?
|
||||
- (void)testBoundary_ExactlyFourConnections_AllKept {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 并发发起4个请求(使用延迟确保同时在飞行中,创建4个独立连接)
|
||||
// 并发发起4个请求(使用延迟确保同时在飞行中,创<EFBFBD><EFBFBD>?个独立连接)
|
||||
NSMutableArray<XCTestExpectation *> *expectations = [NSMutableArray array];
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
@@ -272,7 +272,7 @@
|
||||
|
||||
dispatch_async(queue, ^{
|
||||
NSError *error = nil;
|
||||
// 使用 /delay/2 确保所有请求同时在飞行中
|
||||
// 使用 /delay/2 确保所有请求同时在飞行<EFBFBD><EFBFBD>?
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/delay/2"
|
||||
userAgent:[NSString stringWithFormat:@"Request%ld", (long)i]
|
||||
timeout:15.0
|
||||
@@ -280,7 +280,7 @@
|
||||
[expectation fulfill];
|
||||
});
|
||||
|
||||
[NSThread sleepForTimeInterval:0.05]; // 小间隔避免完全同时启动
|
||||
[NSThread sleepForTimeInterval:0.05]; // 小间隔避免完全同时启<EFBFBD><EFBFBD>?
|
||||
}
|
||||
|
||||
[self waitForExpectations:expectations timeout:20.0];
|
||||
@@ -288,22 +288,22 @@
|
||||
// 等待连接归还
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 验证:池恰好有4个连接(全部保留)
|
||||
// 验证:池恰好<EFBFBD><EFBFBD>?个连接(全部保留<EFBFBD><EFBFBD>?
|
||||
NSUInteger poolCount = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertEqual(poolCount, 4,
|
||||
@"Pool should keep all 4 connections (not exceeding limit)");
|
||||
|
||||
// 验证:恰好创建4个连接
|
||||
// 验证:恰好创<EFBFBD><EFBFBD>?个连<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual(self.client.connectionCreationCount, 4,
|
||||
@"Should create exactly 4 connections");
|
||||
}
|
||||
|
||||
// Q1.2 正常状态序列验证
|
||||
// Q1.2 正常状态序列验<EFBFBD><EFBFBD>?
|
||||
- (void)testStateMachine_NormalSequence_StateTransitionsCorrect {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 第1步:创建并使用连接 (CREATING → IN_USE → IDLE)
|
||||
// <EFBFBD><EFBFBD>?步:创建并使用连<EFBFBD><EFBFBD>?(CREATING <EFBFBD><EFBFBD>?IN_USE <EFBFBD><EFBFBD>?IDLE)
|
||||
HttpdnsNWHTTPClientResponse *response1 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"StateTest"
|
||||
timeout:15.0
|
||||
@@ -312,18 +312,18 @@
|
||||
|
||||
[NSThread sleepForTimeInterval:1.0]; // 等待归还
|
||||
|
||||
// 验证:池中有1个连接
|
||||
// 验证:池中有1个连<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual([self.client connectionPoolCountForKey:poolKey], 1,
|
||||
@"Connection should be in pool");
|
||||
|
||||
// 第2步:复用连接 (IDLE → IN_USE → IDLE)
|
||||
// <EFBFBD><EFBFBD>?步:复用连接 (IDLE <EFBFBD><EFBFBD>?IN_USE <EFBFBD><EFBFBD>?IDLE)
|
||||
HttpdnsNWHTTPClientResponse *response2 = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"StateTest"
|
||||
timeout:15.0
|
||||
error:nil];
|
||||
XCTAssertNotNil(response2, @"Second request should reuse connection");
|
||||
|
||||
// 验证:复用计数增加
|
||||
// 验证:复用计数增<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual(self.client.connectionReuseCount, 1,
|
||||
@"Should have reused connection once");
|
||||
}
|
||||
@@ -333,7 +333,7 @@
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 发起请求并归还
|
||||
// 发起请求并归<EFBFBD><EFBFBD>?
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"InUseTest"
|
||||
timeout:15.0
|
||||
@@ -364,20 +364,20 @@
|
||||
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 获取连接并设置 lastUsedDate 为 nil
|
||||
// 获取连接并设<EFBFBD><EFBFBD>?lastUsedDate <EFBFBD><EFBFBD>?nil
|
||||
NSArray<HttpdnsNWReusableConnection *> *connections = [self.client connectionsInPoolForKey:poolKey];
|
||||
XCTAssertEqual(connections.count, 1, @"Should have connection");
|
||||
|
||||
HttpdnsNWReusableConnection *conn = connections.firstObject;
|
||||
[conn debugSetLastUsedDate:nil];
|
||||
|
||||
// 发起新请求触发 prune(内部应使用 distantPast 处理 nil)
|
||||
// 发起新请求触<EFBFBD><EFBFBD>?prune(内部应使用 distantPast 处理 nil<EFBFBD><EFBFBD>?
|
||||
HttpdnsNWHTTPClientResponse *response = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"NilDateTest"
|
||||
timeout:15.0
|
||||
error:nil];
|
||||
|
||||
// 验证:不崩溃,正常工作
|
||||
// 验证:不崩溃,正常工<EFBFBD><EFBFBD>?
|
||||
XCTAssertNotNil(response, @"Should handle nil lastUsedDate gracefully");
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 发起多个请求(包括成功和超时)
|
||||
// 发起多个请求(包括成功和超时<EFBFBD><EFBFBD>?
|
||||
for (NSInteger i = 0; i < 3; i++) {
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"InvariantTest"
|
||||
@@ -394,7 +394,7 @@
|
||||
error:nil];
|
||||
}
|
||||
|
||||
// 发起1个超时请求
|
||||
// 发起1个超时请<EFBFBD><EFBFBD>?
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/delay/10"
|
||||
userAgent:@"TimeoutTest"
|
||||
timeout:0.5
|
||||
@@ -402,7 +402,7 @@
|
||||
|
||||
[NSThread sleepForTimeInterval:2.0];
|
||||
|
||||
// 获取池中所有连接
|
||||
// 获取池中所有连<EFBFBD><EFBFBD>?
|
||||
NSArray<HttpdnsNWReusableConnection *> *connections = [self.client connectionsInPoolForKey:poolKey];
|
||||
|
||||
// 验证:池中无失效连接
|
||||
@@ -411,12 +411,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Q3.4 lastUsedDate 单调性验证
|
||||
// Q3.4 lastUsedDate 单调性验<EFBFBD><EFBFBD>?
|
||||
- (void)testInvariant_LastUsedDate_Monotonic {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 第1次使用
|
||||
// <EFBFBD><EFBFBD>?次使<EFBFBD><EFBFBD>?
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"MonotonicTest"
|
||||
timeout:15.0
|
||||
@@ -429,10 +429,10 @@
|
||||
NSDate *date1 = connections1.firstObject.lastUsedDate;
|
||||
XCTAssertNotNil(date1, @"lastUsedDate should be set");
|
||||
|
||||
// 等待1秒确保时间推进
|
||||
// 等待1秒确保时间推<EFBFBD><EFBFBD>?
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 第2次使用同一连接
|
||||
// <EFBFBD><EFBFBD>?次使用同一连接
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"MonotonicTest"
|
||||
timeout:15.0
|
||||
@@ -449,12 +449,12 @@
|
||||
@"lastUsedDate should increase after reuse");
|
||||
}
|
||||
|
||||
// Q5.1 超时+池溢出复合场景
|
||||
// Q5.1 超时+池溢出复合场<EFBFBD><EFBFBD>?
|
||||
- (void)testCompound_TimeoutDuringPoolOverflow_Handled {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
|
||||
// 先填满池(4个成功连接)
|
||||
// 先填满池<EFBFBD><EFBFBD>?个成功连接)
|
||||
NSMutableArray<XCTestExpectation *> *expectations = [NSMutableArray array];
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
@@ -477,9 +477,9 @@
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
NSUInteger poolCountBefore = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertLessThanOrEqual(poolCountBefore, 4, @"Pool should have ≤4 connections");
|
||||
XCTAssertLessThanOrEqual(poolCountBefore, 4, @"Pool should have <EFBFBD><EFBFBD>? connections");
|
||||
|
||||
// 第5个请求超时
|
||||
// <EFBFBD><EFBFBD>?个请求超<EFBFBD><EFBFBD>?
|
||||
NSError *error = nil;
|
||||
HttpdnsNWHTTPClientResponse *response = [self.client performRequestWithURLString:@"http://127.0.0.1:11080/delay/10"
|
||||
userAgent:@"TimeoutRequest"
|
||||
@@ -491,7 +491,7 @@
|
||||
|
||||
[NSThread sleepForTimeInterval:1.0];
|
||||
|
||||
// 验证:超时连接未加入池
|
||||
// 验证:超时连接未加入<EFBFBD><EFBFBD>?
|
||||
NSUInteger poolCountAfter = [self.client connectionPoolCountForKey:poolKey];
|
||||
XCTAssertLessThanOrEqual(poolCountAfter, 4, @"Timed-out connection should not be added to pool");
|
||||
}
|
||||
@@ -507,15 +507,15 @@
|
||||
timeout:2.0
|
||||
error:&error];
|
||||
|
||||
// 验证:请求失败
|
||||
// 验证:请求失<EFBFBD><EFBFBD>?
|
||||
XCTAssertNil(response, @"Should fail to connect to invalid port");
|
||||
|
||||
// 验证:无连接加入池
|
||||
// 验证:无连接加入<EFBFBD><EFBFBD>?
|
||||
XCTAssertEqual([self.client totalConnectionCount], 0,
|
||||
@"Failed connection should not be added to pool");
|
||||
}
|
||||
|
||||
// Q2.5 多次 invalidate 幂等性
|
||||
// Q2.5 多次 invalidate 幂等<EFBFBD><EFBFBD>?
|
||||
- (void)testAbnormal_MultipleInvalidate_Idempotent {
|
||||
[self.client resetPoolStatistics];
|
||||
NSString *poolKey = @"127.0.0.1:11080:tcp";
|
||||
@@ -542,11 +542,11 @@
|
||||
XCTAssertTrue(conn.isInvalidated, @"Connection should be invalidated");
|
||||
}
|
||||
|
||||
// Q5.2 并发 dequeue 竞态测试
|
||||
// Q5.2 并发 dequeue 竞态测<EFBFBD><EFBFBD>?
|
||||
- (void)testCompound_ConcurrentDequeueDuringPrune_Safe {
|
||||
[self.client resetPoolStatistics];
|
||||
|
||||
// 在两个端口创建连接
|
||||
// 在两个端口创建连<EFBFBD><EFBFBD>?
|
||||
[self.client performRequestWithURLString:@"http://127.0.0.1:11080/get"
|
||||
userAgent:@"RaceTest"
|
||||
timeout:15.0
|
||||
@@ -562,7 +562,7 @@
|
||||
// 等待30秒让连接过期
|
||||
[NSThread sleepForTimeInterval:30.5];
|
||||
|
||||
// 并发触发两个端口的 dequeue(会触发 prune)
|
||||
// 并发触发两个端口<EFBFBD><EFBFBD>?dequeue(会触发 prune<EFBFBD><EFBFBD>?
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user