带阿里标识的版本

This commit is contained in:
robin
2026-02-28 18:55:33 +08:00
parent 150799f41d
commit 5d0b7c7e91
477 changed files with 10813 additions and 4044 deletions

View File

@@ -1,9 +1,9 @@
//
// CacheKeyFunctionTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/6/12.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -70,7 +70,7 @@ static NSString *sdnsHost = @"sdns1.onlyforhttpdnstest.run.place";
//
[self.httpdns.requestManager cleanAllHostMemoryCache];
// db
// db<EFBFBD><EFBFBD>?
[self.httpdns.requestManager syncLoadCacheFromDbToMemory];
HttpdnsResult *result = [self.httpdns resolveHostSyncNonBlocking:testHost byIpType:HttpdnsQueryIPTypeIpv4];

View File

@@ -1,9 +1,9 @@
//
// CustomTTLAndCleanCacheTest.m
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by xuyecan on 2024/6/17.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -38,8 +38,8 @@ static int TEST_CUSTOM_TTL_SECOND = 3;
[super tearDown];
}
- (int64_t)httpdnsHost:(NSString *)host ipType:(AlicloudHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// ttl3
- (int64_t)httpdnsHost:(NSString *)host ipType:(TrustHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// ttl<EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>?
NSString *testHost = hostNameIpPrefixMap.allKeys.firstObject;
if ([host isEqual:testHost]) {
return TEST_CUSTOM_TTL_SECOND;

View File

@@ -1,9 +1,9 @@
//
// EnableReuseExpiredIpTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/5/28.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -39,8 +39,8 @@ static int ttlForTest = 3;
self.currentTimeStamp = [[NSDate date] timeIntervalSince1970];
}
- (int64_t)httpdnsHost:(NSString *)host ipType:(AlicloudHttpDNS_IPType)ipType ttl:(int64_t)ttl {
//
- (int64_t)httpdnsHost:(NSString *)host ipType:(TrustHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// <EFBFBD><EFBFBD>?
return ttlForTest;
}
@@ -73,7 +73,7 @@ static int ttlForTest = 3;
XCTAssertTrue([result2.host isEqualToString:host]);
XCTAssertGreaterThan(result2.ttl, 0);
XCTAssertLessThanOrEqual(result2.ttl, ttlForTest);
//
// <EFBFBD><EFBFBD>?
XCTAssertGreaterThan([[NSDate date] timeIntervalSince1970], result2.lastUpdatedTimeInterval + result2.ttl);
NSString *firstIp2 = [result2 firstIpv4Address];
XCTAssertTrue([firstIp2 hasPrefix:ipPrefix]);
@@ -81,13 +81,13 @@ static int ttlForTest = 3;
//
[NSThread sleepForTimeInterval:1];
// 使nonblocking
// 使nonblocking<EFBFBD><EFBFBD>?
HttpdnsResult *result3 = [self.httpdns resolveHostSyncNonBlocking:host byIpType:HttpdnsQueryIPTypeIpv4];
XCTAssertNotNil(result3);
XCTAssertTrue([result3.host isEqualToString:host]);
XCTAssertGreaterThan(result3.ttl, 0);
XCTAssertLessThanOrEqual(result3.ttl, ttlForTest);
//
// <EFBFBD><EFBFBD>?
XCTAssertLessThan([[NSDate date] timeIntervalSince1970], result3.lastUpdatedTimeInterval + result3.ttl);
NSString *firstIp3 = [result3 firstIpv4Address];
XCTAssertTrue([firstIp3 hasPrefix:ipPrefix]);

View File

@@ -1,9 +1,9 @@
//
// HttpdnsHostObjectTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2025/3/14.
// Copyright © 2025 alibaba-inc.com. All rights reserved.
// Copyright © 2025 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -26,19 +26,19 @@
[super tearDown];
}
#pragma mark -
#pragma mark - <EFBFBD><EFBFBD>?
- (void)testHostObjectProperties {
// HttpdnsHostObject
HttpdnsHostObject *hostObject = [[HttpdnsHostObject alloc] init];
//
// <EFBFBD><EFBFBD>?
hostObject.host = @"example.com";
hostObject.ttl = 60;
hostObject.queryTimes = 1;
hostObject.clientIP = @"192.168.1.1";
//
// <EFBFBD><EFBFBD>?
XCTAssertEqualObjects(hostObject.host, @"example.com", @"host属性应该被正确设置");
XCTAssertEqual(hostObject.ttl, 60, @"ttl属性应该被正确设置");
XCTAssertEqual(hostObject.queryTimes, 1, @"queryTimes属性应该被正确设置");
@@ -51,13 +51,13 @@
// HttpdnsIpObject
HttpdnsIpObject *ipObject = [[HttpdnsIpObject alloc] init];
//
// <EFBFBD><EFBFBD>?
ipObject.ip = @"1.2.3.4";
ipObject.ttl = 300;
ipObject.priority = 10;
ipObject.detectRT = 50; // detectRT
ipObject.detectRT = 50; // detectRT<EFBFBD><EFBFBD>?
//
// <EFBFBD><EFBFBD>?
XCTAssertEqualObjects(ipObject.ip, @"1.2.3.4", @"ip属性应该被正确设置");
XCTAssertEqual(ipObject.ttl, 300, @"ttl属性应该被正确设置");
XCTAssertEqual(ipObject.priority, 10, @"priority属性应该被正确设置");
@@ -68,18 +68,18 @@
// HttpdnsIpObject
HttpdnsIpObject *ipObject = [[HttpdnsIpObject alloc] init];
//
// <EFBFBD><EFBFBD>?
XCTAssertEqual(ipObject.detectRT, -1, @"detectRT的默认值应该是-1");
//
// <EFBFBD><EFBFBD>?
[ipObject setDetectRT:100];
XCTAssertEqual(ipObject.detectRT, 100, @"detectRT应该被正确设置为100");
//
// <EFBFBD><EFBFBD>?
[ipObject setDetectRT:-5];
XCTAssertEqual(ipObject.detectRT, -1, @"设置负值时detectRT应该被设置为-1");
// 0
// <EFBFBD><EFBFBD>?
[ipObject setDetectRT:0];
XCTAssertEqual(ipObject.detectRT, 0, @"detectRT应该被正确设置为0");
}
@@ -102,15 +102,15 @@
ipv6Object.ttl = 600;
ipv6Object.detectRT = 80;
// IP
// IP<EFBFBD><EFBFBD>?
[hostObject addIpv4:ipv4Object];
[hostObject addIpv6:ipv6Object];
// IP
XCTAssertEqual(hostObject.ipv4List.count, 1, @"应该有1个IPv4对象");
XCTAssertEqual(hostObject.ipv6List.count, 1, @"应该有1个IPv6对象");
// IP<EFBFBD><EFBFBD>?
XCTAssertEqual(hostObject.ipv4List.count, 1, @"应该<EFBFBD><EFBFBD>?个IPv4对象");
XCTAssertEqual(hostObject.ipv6List.count, 1, @"应该<EFBFBD><EFBFBD>?个IPv6对象");
// IP
// IP<EFBFBD><EFBFBD>?
HttpdnsIpObject *retrievedIpv4 = hostObject.ipv4List.firstObject;
XCTAssertEqualObjects(retrievedIpv4.ip, @"1.2.3.4", @"IPv4地址应该正确");
XCTAssertEqual(retrievedIpv4.detectRT, 50, @"IPv4的detectRT应该正确");
@@ -127,7 +127,7 @@
HttpdnsHostObject *hostObject = [[HttpdnsHostObject alloc] init];
hostObject.host = @"example.com";
// IP
// IP<EFBFBD><EFBFBD>?
HttpdnsIpObject *ip1 = [[HttpdnsIpObject alloc] init];
ip1.ip = @"1.1.1.1";
ip1.detectRT = 100;
@@ -142,7 +142,7 @@
HttpdnsIpObject *ip4 = [[HttpdnsIpObject alloc] init];
ip4.ip = @"4.4.4.4";
ip4.detectRT = -1; //
ip4.detectRT = -1; // <EFBFBD><EFBFBD>?
// IP
[hostObject addIpv4:ip1];
@@ -155,11 +155,11 @@
//
// ip2(50ms) -> ip1(100ms) -> ip3(200ms) -> ip4(-1ms)
XCTAssertEqual(sortedIps.count, 4, @"应该有4个IP对象");
XCTAssertEqualObjects(sortedIps[0].ip, @"2.2.2.2", @"检测时间最短的IP应该排在第一位");
XCTAssertEqualObjects(sortedIps[1].ip, @"1.1.1.1", @"检测时间第二短的IP应该排在第二位");
XCTAssertEqualObjects(sortedIps[2].ip, @"3.3.3.3", @"检测时间第三短的IP应该排在第三位");
XCTAssertEqualObjects(sortedIps[3].ip, @"4.4.4.4", @"未检测的IP应该排在最后");
XCTAssertEqual(sortedIps.count, 4, @"应该<EFBFBD><EFBFBD>?个IP对象");
XCTAssertEqualObjects(sortedIps[0].ip, @"2.2.2.2", @"IP<EFBFBD><EFBFBD>?);
XCTAssertEqualObjects(sortedIps[1].ip, @"1.1.1.1", @"IP<EFBFBD><EFBFBD>?);
XCTAssertEqualObjects(sortedIps[2].ip, @"3.3.3.3", @"IP<EFBFBD><EFBFBD>?);
XCTAssertEqualObjects(sortedIps[3].ip, @"4.4.4.4", @"IP<EFBFBD><EFBFBD>?);
}
@end
@end

View File

@@ -1,9 +1,9 @@
//
// ManuallyCleanCacheTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/6/17.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -1,9 +1,9 @@
//
// MultithreadCorrectnessTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/5/26.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -36,7 +36,7 @@
[super tearDown];
}
// 线
// 线<EFBFBD><EFBFBD>?
- (void)testNoneBlockingMethodShouldNotBlock {
HttpdnsRequestManager *requestManager = self.httpdns.requestManager;
HttpdnsRequestManager *mockedScheduler = OCMPartialMock(requestManager);
@@ -132,7 +132,7 @@
OCMStub([mockResolver resolve:[OCMArg any] error:(NSError * __autoreleasing *)[OCMArg anyPointer]])
.ignoringNonObjectArgs()
.andDo(^(NSInvocation *invocation) {
// 1.5
// 1.5<EFBFBD><EFBFBD>?
[NSThread sleepForTimeInterval:1.5];
[invocation setReturnValue:&mockResolverHostObjects];
});
@@ -146,7 +146,7 @@
[self.httpdns resolveHostSync:ipv4OnlyHost byIpType:HttpdnsQueryIPTypeIpv4];
});
//
// <EFBFBD><EFBFBD>?
[NSThread sleepForTimeInterval:0.5];
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
@@ -156,7 +156,7 @@
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//
//
// 1
// <EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>?
HttpdnsResult *result = [self.httpdns resolveHostSync:ipv4OnlyHost byIpType:HttpdnsQueryIPTypeIpv4];
XCTAssertNotNil(result);
XCTAssertTrue([result.host isEqualToString:ipv4OnlyHost]);
@@ -171,7 +171,7 @@
XCTAssert(elapsedTime >= 1, @"elapsedTime should be more than 1s, but is %f", elapsedTime);
XCTAssert(elapsedTime <= 1.5, @"elapsedTime should not be more than 1.5s, but is %f", elapsedTime);
// TODO
// TODO <EFBFBD><EFBFBD>?
// XCTAssert(elapsedTime < 4.1, @"elapsedTime should be less than 4.1s, but is %f", elapsedTime);
}
@@ -191,7 +191,7 @@
//
@throw [NSException exceptionWithName:@"TestException" reason:@"TestException" userInfo:nil];
} else {
//
// <EFBFBD><EFBFBD>?
[NSThread sleepForTimeInterval:0.4];
[invocation setReturnValue:&mockResolverHostObjects];
}
@@ -206,7 +206,7 @@
[self.httpdns resolveHostSync:ipv4OnlyHost byIpType:HttpdnsQueryIPTypeIpv4];
});
//
// <EFBFBD><EFBFBD>?
[NSThread sleepForTimeInterval:0.2];
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
@@ -215,8 +215,8 @@
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//
//
// 5
// <EFBFBD><EFBFBD>?
// 5<EFBFBD><EFBFBD>?
HttpdnsResult *result = [self.httpdns resolveHostSync:ipv4OnlyHost byIpType:HttpdnsQueryIPTypeIpv4];
XCTAssertNotNil(result);
XCTAssertTrue([result.host isEqualToString:ipv4OnlyHost]);
@@ -232,7 +232,7 @@
XCTAssert(elapsedTime < 0.8, @"elapsedTime should be less than 0.8s, but is %f", elapsedTime);
}
//
// <EFBFBD><EFBFBD>?
- (void)testSyncMethodSetBlockTimeout {
HttpdnsRequestManager *requestManager = self.httpdns.requestManager;
[self.httpdns cleanAllHostCache];
@@ -266,7 +266,7 @@
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
// 0.5 - 5
// <EFBFBD><EFBFBD>?.5 - 5<EFBFBD><EFBFBD>?
- (void)testLimitResolveTimeoutRange {
HttpdnsRequest *request = [HttpdnsRequest new];
request.host = ipv4OnlyHost;
@@ -285,7 +285,7 @@
XCTAssertEqual(request.resolveTimeoutInSecond, 3.5);
}
//
// <EFBFBD><EFBFBD>?
- (void)testAsyncMethodSetBlockTimeout {
HttpdnsRequestManager *requestManager = self.httpdns.requestManager;
[self.httpdns cleanAllHostCache];
@@ -318,7 +318,7 @@
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
// 线线
// 线线<EFBFBD><EFBFBD>?
- (void)testMultiThreadSyncMethodMaxBlockingTime {
HttpdnsRequestManager *requestManager = self.httpdns.requestManager;
[self.httpdns cleanAllHostCache];

View File

@@ -1,9 +1,9 @@
//
// PresetCacheAndRetrieveTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/5/26.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -16,7 +16,7 @@
/**
* 使OCMockMock(使stopMocking)
* case
* case<EFBFBD><EFBFBD>?
*/
@interface PresetCacheAndRetrieveTest : TestBase
@@ -122,7 +122,7 @@
XCTAssertTrue([result.ipv6s[0] isEqualToString:ipv61]);
// autoipv6only
// ipv4autoipv6ipv6
// ipv4autoipv6ipv6<EFBFBD><EFBFBD>?
// ipv4+ipv6
result = [self.httpdns resolveHostSyncNonBlocking:ipv4AndIpv6Host byIpType:HttpdnsQueryIPTypeAuto];
@@ -180,7 +180,7 @@
XCTAssertTrue([result.ipv6s[0] isEqualToString:ipv61]);
}
// ttllastLookupTimeipv4ipv6
// ttllastLookupTimeipv4ipv6<EFBFBD><EFBFBD>?
- (void)testTTLAndLastLookUpTime {
[self presetNetworkEnvAsIpv4AndIpv6];
[self.httpdns cleanAllHostCache];
@@ -195,7 +195,7 @@
hostObject1.lastIPv4LookupTime = currentTimestamp - 1;
hostObject1.lastIPv6LookupTime = currentTimestamp - 2;
//
// <EFBFBD><EFBFBD>?
[self.httpdns.requestManager mergeLookupResultToManager:hostObject1 host:ipv4AndIpv6Host cacheKey:ipv4AndIpv6Host underQueryIpType:HttpdnsQueryIPTypeBoth];
// autoipv4ipv6
@@ -210,10 +210,10 @@
hostObject2.v4ttl = 600;
hostObject2.lastIPv4LookupTime = currentTimestamp - 10;
// ipv4
// ipv4<EFBFBD><EFBFBD>?
[self.httpdns.requestManager mergeLookupResultToManager:hostObject2 host:ipv4AndIpv6Host cacheKey:ipv4AndIpv6Host underQueryIpType:HttpdnsQueryIPTypeIpv4];
// v4v6
// v4v6<EFBFBD><EFBFBD>?
result = [self.httpdns resolveHostSyncNonBlocking:ipv4AndIpv6Host byIpType:HttpdnsQueryIPTypeAuto];
XCTAssertEqual(result.ttl, hostObject2.v4ttl);
XCTAssertEqual(result.lastUpdatedTimeInterval, hostObject2.lastIPv4LookupTime);
@@ -222,7 +222,7 @@
}
// ipv4ipv6
// ipv6ipv6
// ipv6ipv6<EFBFBD><EFBFBD>?
- (void)testMergeNoIpv6ResultAndGetBoth {
[self presetNetworkEnvAsIpv4AndIpv6];

View File

@@ -1,9 +1,9 @@
//
// ResolvingEffectiveHostTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/5/28.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -42,8 +42,8 @@
[super tearDown];
}
- (int64_t)httpdnsHost:(NSString *)host ipType:(AlicloudHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// ttl1-4
- (int64_t)httpdnsHost:(NSString *)host ipType:(TrustHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// ttl<EFBFBD><EFBFBD>?-4<EFBFBD><EFBFBD>?
return arc4random_uniform(4) + 1;
}
@@ -87,7 +87,7 @@
long long executeStartTimeInMs = [[NSDate date] timeIntervalSince1970] * 1000;
HttpdnsResult *result = [self.httpdns resolveHostSyncNonBlocking:host byIpType:HttpdnsQueryIPTypeIpv4];
long long executeEndTimeInMs = [[NSDate date] timeIntervalSince1970] * 1000;
// 30ms
// <EFBFBD><EFBFBD>?0ms
if (executeEndTimeInMs - executeStartTimeInMs >= 30) {
printf("XCTAssertWillFailed, host: %s, executeTime: %lldms\n", [host UTF8String], executeEndTimeInMs - executeStartTimeInMs);
}

View File

@@ -1,9 +1,9 @@
//
// ScheduleCenterV4Test.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/6/16.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -20,7 +20,7 @@
/**
* 使OCMockMock(使stopMocking)
* case
* case<EFBFBD><EFBFBD>?
*/
@interface ScheduleCenterV4Test : TestBase

View File

@@ -1,9 +1,9 @@
//
// ScheduleCenterV6Test.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/6/17.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <OCMock/OCMock.h>
@@ -18,7 +18,7 @@
/**
* 使OCMockMock(使stopMocking)
* case
* case<EFBFBD><EFBFBD>?
*/
@interface ScheduleCenterV6Test : TestBase

View File

@@ -1,9 +1,9 @@
//
// SdnsScenarioTest.m
// AlicloudHttpDNSTests
// TrustHttpDNSTests
//
// Created by xuyecan on 2024/5/29.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -41,8 +41,8 @@ static NSString *sdnsHost = @"sdns1.onlyforhttpdnstest.run.place";
self.currentTimeStamp = [[NSDate date] timeIntervalSince1970];
}
- (int64_t)httpdnsHost:(NSString *)host ipType:(AlicloudHttpDNS_IPType)ipType ttl:(int64_t)ttl {
//
- (int64_t)httpdnsHost:(NSString *)host ipType:(TrustHttpDNS_IPType)ipType ttl:(int64_t)ttl {
// <EFBFBD><EFBFBD>?
return ttlForTest;
}