Skip to content

Commit 04d4ed5

Browse files
committed
optimize test case
1 parent 215c350 commit 04d4ed5

22 files changed

+110
-100
lines changed

QiniuSDK/Storage/QNConfiguration.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (void)setupData{
9393
_partialHostFrozenTime = 5*60;
9494

9595
_connectCheckTimeout = 3;
96-
_connectCheckURLStrings = @[@"http://www.qiniu.com", @"http://www.baidu.com", @"http://www.google.com"];
96+
_connectCheckURLStrings = @[@"https://www.qiniu.com", @"https://www.baidu.com", @"https://www.google.com"];
9797
}
9898

9999
@end

QiniuSDKTests/QNAutoZoneTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ - (void)testHttp {
4747
c = code;
4848
}];
4949
AGWW_WAIT_WHILE(x == 0, 100.0);
50-
XCTAssertEqual(0, c, @"Pass");
50+
XCTAssertEqual(0, c, @"c: %d", c);
5151
}
5252

5353
- (void)testMutiHttp{

QiniuSDKTests/QNBase64Test.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ @implementation QNBase64Test
1818
- (void)testEncode {
1919
// This is an example of a functional test case.
2020
NSString *source = @"你好/+=";
21-
22-
XCTAssert([[QNUrlSafeBase64 encodeString:source] isEqual:@"5L2g5aW9Lys9"], @"Pass");
21+
NSString *encode = [QNUrlSafeBase64 encodeString:source];
22+
XCTAssert([encode isEqual:@"5L2g5aW9Lys9"], @"encode: %@", encode);
2323
}
2424

2525
@end

QiniuSDKTests/QNCFHttpClientTest.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ - (void)onError:(nonnull NSError *)error {
186186

187187
- (void)onReceiveResponse:(nonnull NSURLResponse *)response {
188188
NSHTTPURLResponse *responseP = (NSHTTPURLResponse *)response;
189-
NSLog(@"statusCode: %ld \r\n header: %@", responseP.statusCode, responseP.allHeaderFields);
190-
XCTAssert(responseP.statusCode == 200, @"Pass");
189+
NSString *responseInfo = [NSString stringWithFormat:@"statusCode: %ld \r\n header: %@", responseP.statusCode, responseP.allHeaderFields];
190+
NSLog(@"responseInfo: %@", responseInfo);
191+
XCTAssert(responseP.statusCode == 200, @"response: %@", responseInfo);
191192
}
192193

193194
- (void)redirectedToRequest:(nonnull NSURLRequest *)request redirectResponse:(nonnull NSURLResponse *)redirectResponse {

QiniuSDKTests/QNComplexUploadSceneTest.m

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ - (void)testMutiUploadV1{
2929
builder.concurrentTaskCount = 3;
3030
builder.chunkSize = (i%4 + 1) * 1014 * 1024 + i;
3131
}];
32-
int size = (i + 1) * 1024;
32+
int size = (i + 1) * 50;
3333
NSString *keyUp = [NSString stringWithFormat:@"complex_upload_v1_%dk", size];
3434
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 1024 identifier:keyUp];
3535
[self uploadFile:tempFile key:keyUp config:config option:nil complete:^(QNResponseInfo * _Nonnull responseInfo, NSString * _Nonnull key) {
36+
NSLog(@"complex_upload v1 response info: %@", responseInfo);
3637
@synchronized (self) {
3738
if (responseInfo.isOK) {
3839
successCount += 1;
@@ -45,28 +46,30 @@ - (void)testMutiUploadV1{
4546
AGWW_WAIT_WHILE(completeCount != (maxCount - start), 600 * 10);
4647

4748
NSLog(@"complex_upload v1 successCount: %d", successCount);
48-
XCTAssert(completeCount == (maxCount - start), @"Pass");
49+
XCTAssertTrue(completeCount == successCount, @"complete count:%d success count:%d", completeCount, successCount);
50+
XCTAssertTrue(completeCount == (maxCount - start), @"complete count:%d total count:%d", completeCount, (maxCount - start));
4951
}
5052

5153
- (void)test100UploadV1{
5254
int maxCount = 100;
5355
__block int completeCount = 0;
5456
__block int successCount = 0;
5557

56-
int start = 0;
58+
int start = 50;
5759
for (int i=start; i<maxCount; i++) {
5860
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
5961
builder.resumeUploadVersion = QNResumeUploadVersionV1;
6062
builder.useConcurrentResumeUpload = YES;
6163
builder.concurrentTaskCount = 3;
62-
builder.chunkSize = (i%4 + 1) * 1014 * 1024 + i;
64+
builder.chunkSize = 4 * 1014 * 1024;
6365
}];
64-
int size = (i + 1) * 1024;
66+
int size = (i + 1) * 50;
6567
NSString *keyUp = [NSString stringWithFormat:@"complex_100_upload_v1_%dk", size];
66-
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 50 identifier:keyUp];
68+
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 1024 identifier:keyUp];
6769
[self uploadFile:tempFile key:keyUp config:config option:nil complete:^(QNResponseInfo * _Nonnull responseInfo, NSString * _Nonnull key) {
70+
NSLog(@"complex_100_upload v1 response info: %@", responseInfo);
6871
@synchronized (self) {
69-
if (responseInfo.isOK) {
72+
if (responseInfo.isOK || responseInfo.statusCode == 614) {
7073
successCount += 1;
7174
}
7275
completeCount += 1;
@@ -77,7 +80,8 @@ - (void)test100UploadV1{
7780
AGWW_WAIT_WHILE(completeCount != (maxCount - start), 600 * 10);
7881

7982
NSLog(@"complex_100_upload v1 successCount: %d", successCount);
80-
XCTAssert(completeCount == (maxCount - start), @"Pass");
83+
XCTAssertTrue(completeCount == successCount, @"complete count:%d success count:%d", completeCount, successCount);
84+
XCTAssertTrue(completeCount == (maxCount - start), @"complete count:%d total count:%d", completeCount, (maxCount - start));
8185
}
8286

8387
- (void)testMutiUploadV2{
@@ -93,10 +97,11 @@ - (void)testMutiUploadV2{
9397
builder.concurrentTaskCount = 3;
9498
builder.chunkSize = (i%4 + 1) * 1024 * 1024 + i;
9599
}];
96-
int size = (i + 1) * 1024;
100+
int size = (i + 1) * 50;
97101
NSString *keyUp = [NSString stringWithFormat:@"complex_upload_v2_%dk", size];
98102
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 1024 identifier:keyUp];
99103
[self uploadFile:tempFile key:keyUp config:config option:nil complete:^(QNResponseInfo * _Nonnull responseInfo, NSString * _Nonnull key) {
104+
NSLog(@"complex_upload v2 response info: %@", responseInfo);
100105
@synchronized (self) {
101106
if (responseInfo.isOK) {
102107
successCount += 1;
@@ -109,28 +114,30 @@ - (void)testMutiUploadV2{
109114
AGWW_WAIT_WHILE(completeCount != (maxCount - start), 600 * 30);
110115

111116
NSLog(@"complex_upload v2 successCount: %d", successCount);
112-
XCTAssert(completeCount == (maxCount - start), @"Pass");
117+
XCTAssertTrue(completeCount == successCount, @"complete count:%d success count:%d", completeCount, successCount);
118+
XCTAssertTrue(completeCount == (maxCount - start), @"complete count:%d total count:%d", completeCount, (maxCount - start));
113119
}
114120

115121
- (void)test100UploadV2{
116122
int maxCount = 100;
117123
__block int completeCount = 0;
118124
__block int successCount = 0;
119125

120-
int start = 0;
126+
int start = 50;
121127
for (int i=start; i<maxCount; i++) {
122128
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
123129
builder.resumeUploadVersion = QNResumeUploadVersionV2;
124130
builder.useConcurrentResumeUpload = YES;
125131
builder.concurrentTaskCount = 3;
126-
builder.chunkSize = (i%4 + 1) * 1024 * 1024 + i;
132+
builder.chunkSize = 4 * 1024 * 1024 + i;
127133
}];
128-
int size = (i + 1) * 1024;
134+
int size = (i + 1) * 50;
129135
NSString *keyUp = [NSString stringWithFormat:@"complex_100_upload_v2_%dk", size];
130-
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 50 identifier:keyUp];
136+
QNTempFile *tempFile = [QNTempFile createTempFileWithSize:size * 1024 identifier:keyUp];
131137
[self uploadFile:tempFile key:keyUp config:config option:nil complete:^(QNResponseInfo * _Nonnull responseInfo, NSString * _Nonnull key) {
138+
NSLog(@"complex_100_upload v2 response info: %@", responseInfo);
132139
@synchronized (self) {
133-
if (responseInfo.isOK) {
140+
if (responseInfo.isOK || responseInfo.statusCode == 614) {
134141
successCount += 1;
135142
}
136143
completeCount += 1;
@@ -141,7 +148,8 @@ - (void)test100UploadV2{
141148
AGWW_WAIT_WHILE(completeCount != (maxCount - start), 600 * 30);
142149

143150
NSLog(@"complex_100_upload v2 successCount: %d", successCount);
144-
XCTAssert(completeCount == (maxCount - start), @"Pass");
151+
XCTAssertTrue(completeCount == successCount, @"complete count:%d success count:%d", completeCount, successCount);
152+
XCTAssertTrue(completeCount == (maxCount - start), @"complete count:%d total count:%d", completeCount, (maxCount - start));
145153
}
146154

147155
@end

QiniuSDKTests/QNConnctCheckTest.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void)testCheck {
3434
}
3535
}
3636

37-
XCTAssertTrue(maxCount == successCount, @"Pass");
37+
XCTAssertTrue(maxCount == successCount, @"maxCount:%d successCount:%d", maxCount, successCount);
3838
}
3939

4040
- (void)testCustomCheckHosts {
@@ -48,7 +48,7 @@ - (void)testCustomCheckHosts {
4848
}
4949
}
5050

51-
XCTAssertTrue(maxCount == successCount, @"Pass");
51+
XCTAssertTrue(maxCount == successCount, @"maxCount:%d successCount:%d", maxCount, successCount);
5252
}
5353

5454
- (void)testNotConnected {
@@ -62,7 +62,7 @@ - (void)testNotConnected {
6262
}
6363
}
6464

65-
XCTAssertTrue(successCount == 0, @"Pass");
65+
XCTAssertTrue(successCount == 0, @"successCount:%d", successCount);
6666
}
6767

6868
@end

QiniuSDKTests/QNCrc32Test.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ - (void)testData {
2020
NSData *buffer = [@"Hello, World!" dataUsingEncoding:NSUTF8StringEncoding];
2121
UInt32 crc = [QNCrc32 data:buffer];
2222

23-
XCTAssert(crc == 3964322768, @"Pass");
23+
XCTAssertTrue(crc == 3964322768, @"crc: %d", crc);
2424
}
2525

2626
- (void)testFile {
2727
NSError *error;
2828
QNTempFile *file = [QNTempFile createTempFileWithSize:5 * 1024 * 1024 identifier:@"crc_5M"];
2929
UInt32 u = [QNCrc32 file:[file.fileUrl relativePath] error:&error];
3030

31-
XCTAssert(u == 1630269785, @"Pass");
31+
XCTAssertTrue(u == 1630269785, @"u: %d", u);
3232
[file remove];
3333
}
3434

QiniuSDKTests/QNDnsPrefetcherTest.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)testLocalLoad {
7979
QN_TEST_CASE_WAIT_TIME(5);
8080

8181
NSArray <id <QNIDnsNetworkAddress>> *addressList = [kQNDnsPrefetch getInetAddressByHost:host];
82-
XCTAssert(addressList.count > 0, @"success");
82+
XCTAssert(addressList.count > 0, @"addressList count:%ld", addressList.count);
8383
}
8484

8585
- (void)testPreFetch {
@@ -89,7 +89,7 @@ - (void)testPreFetch {
8989
AGWW_WAIT_WHILE([kQNDnsPrefetch getInetAddressByHost:kCustomHost] == nil, 60 * 5);
9090

9191
NSArray <id <QNIDnsNetworkAddress>> *addressList = [kQNDnsPrefetch getInetAddressByHost:kCustomHost];
92-
XCTAssert(addressList.count > 0, @"success");
92+
XCTAssert(addressList.count > 0, @"addressList count:%ld", addressList.count);
9393
}
9494

9595
- (void)notestCustomDns {
@@ -101,7 +101,7 @@ - (void)notestCustomDns {
101101

102102
NSArray <id <QNIDnsNetworkAddress>> *addressList = [kQNDnsPrefetch getInetAddressByHost:kCustomHost];
103103
NSLog(@"addressList count: %ld", addressList.count);
104-
XCTAssert(addressList.count==1, @"success");
104+
XCTAssert(addressList.count==1, @"addressList count:%ld", addressList.count);
105105
XCTAssert([addressList.firstObject.ipValue isEqualToString:CustomIPValue], @"success");
106106
}
107107

@@ -120,7 +120,7 @@ - (void)notestDefaultTTL {
120120

121121
NSArray <id <QNIDnsNetworkAddress>> *addressList = [kQNDnsPrefetch getInetAddressByHost:kCustomHost];
122122

123-
XCTAssert(addressList.count==1, @"success");
123+
XCTAssert(addressList.count==1, @"addressList count:%ld", addressList.count);
124124
XCTAssert(addressList.firstObject.ttlValue.doubleValue == 120, @"success");
125125

126126
}
@@ -150,7 +150,7 @@ - (void)testMutiThreadPrefetch{
150150
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
151151
// 1 or 0
152152
NSLog(@"successPrefetchNum: %d", successPrefetchNum);
153-
XCTAssert(successPrefetchNum >= 0, @"success");
153+
XCTAssert(successPrefetchNum >= 0, @"successPrefetchNum:%d", successPrefetchNum);
154154
});
155155

156156
QN_TEST_CASE_WAIT_TIME(2);

QiniuSDKTests/QNEtagTest.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ @interface QNEtagTest : XCTestCase
1818
@implementation QNEtagTest
1919

2020
- (void)testEtagZero {
21-
XCTAssert([@"Fto5o-5ea0sNMlW_75VgGJCv2AcJ" isEqualToString:[QNEtag data:nil]], @"Pass");
21+
NSString *etag = [QNEtag data:nil];
22+
XCTAssert([@"Fto5o-5ea0sNMlW_75VgGJCv2AcJ" isEqualToString:etag], @"etag:%@", etag);
2223
}
2324

2425
- (void)testFile5M {

QiniuSDKTests/QNFileRecorderTest.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ - (void)setUp {
3939
- (void)testInit {
4040
NSError *error = nil;
4141
[QNFileRecorder fileRecorderWithFolder:[NSTemporaryDirectory() stringByAppendingString:@"qiniutest"] error:&error];
42-
XCTAssert(error == nil, @"Pass");
42+
XCTAssert(error == nil, @"error 1:%@", error);
4343
[QNFileRecorder fileRecorderWithFolder:@"/qiniutest" error:&error];
4444
NSLog(@"file recorder %@", error);
45-
XCTAssert(error != nil, @"Pass");
45+
XCTAssert(error != nil, @"error 2:%@", error);
4646
[QNFileRecorder fileRecorderWithFolder:@"/qiniutest" error:nil];
4747
}
4848

@@ -71,8 +71,8 @@ - (void) template:(int)size pos:(float)pos {
7171
option:opt];
7272
AGWW_WAIT_WHILE(key == nil, 60 * 30);
7373
NSLog(@"%@ info %@", keyUp, info);
74-
XCTAssert(info.isCancelled, @"Pass");
75-
XCTAssert([keyUp isEqualToString:key], @"Pass");
74+
XCTAssert(info.isCancelled, @"cancel info:%@", info);
75+
XCTAssert([keyUp isEqualToString:key], @"cancel keyUp:%@ key:%@", keyUp, key);
7676

7777
// continue
7878
key = nil;
@@ -95,9 +95,9 @@ - (void) template:(int)size pos:(float)pos {
9595
NSLog(@"failed: %@", failed ? @"YES" : @"NO");
9696
AGWW_WAIT_WHILE(key == nil, 60 * 30);
9797
NSLog(@"info %@", info);
98-
XCTAssert(info.isOK, @"Pass");
99-
XCTAssert(!failed, @"Pass");
100-
XCTAssert([keyUp isEqualToString:key], @"Pass");
98+
XCTAssert(info.isOK, @"continue info: %@", info);
99+
XCTAssert(!failed, @"continue info: %@", info);
100+
XCTAssert([keyUp isEqualToString:key], @"continue keyUp:%@ key:%@", keyUp, key);
101101
[tempFile remove];
102102
}
103103

0 commit comments

Comments
 (0)