@@ -50,6 +50,55 @@ - (void)testUp {
5050 XCTAssert (testInfo.reqId , @" Pass" );
5151}
5252
53+ // upload 100 file and calculate upload success rate
54+ - (void )test100Up {
55+ NSInteger count = 100 ;
56+ __block NSInteger completeCount = 0 ;
57+ __block NSInteger successCount = 0 ;
58+ for (int i=0 ; i<count; i++) {
59+ NSString *taskId = [NSString stringWithFormat: @" test100Up_%d " , i];
60+ [self test100UpTask: taskId complete: ^(BOOL isSuccess) {
61+ @synchronized (self) {
62+ if (isSuccess) {
63+ successCount += 1 ;
64+ }
65+ completeCount += 1 ;
66+ NSLog (@" upload file: test100Up_%d " , i);
67+ }
68+ }];
69+ }
70+
71+ AGWW_WAIT_WHILE (completeCount != count, 100.0 );
72+
73+ CGFloat successRate = successCount * 1.0 / count;
74+ NSLog (@" successCount: %td " , successCount);
75+ NSLog (@" successRate: %lf " , successRate);
76+ XCTAssert (completeCount == count, @" Pass" );
77+ }
78+
79+ - (void )test100UpTask : (NSString *)taskId complete : (void (^)(BOOL isSuccess))complete {
80+ QNConfiguration *config = [QNConfiguration build: ^(QNConfigurationBuilder *builder) {
81+ builder.timeoutInterval = 5 ;
82+ }];
83+ QNUploadManager *upManager = [[QNUploadManager alloc ]initWithConfiguration:config];
84+ QNUploadOption *opt = [[QNUploadOption alloc ] initWithMime: @" text/plain" progressHandler: nil params: @{ @" x:foo" : @" bar" } checkCrc: YES cancellationSignal: nil ];
85+ NSMutableString *contentString = [NSMutableString string ];
86+ NSString *word = @" Hello, World!" ;
87+ while (contentString.length < 1024 ) {
88+ [contentString appendString: word];
89+ }
90+ NSData *data = [[contentString copy ] dataUsingEncoding: NSUTF8StringEncoding];
91+ [upManager putData: data key: taskId token: g_token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
92+ if (info.isOK && info.reqId ) {
93+ complete (YES );
94+ } else {
95+ NSLog (@" upload failed. response info is: %@ " ,info);
96+ complete (NO );
97+ }
98+ } option: opt];
99+ }
100+
101+
53102// travis ci iOS simulator 8.1 failed,其他环境(mac, iOS 9.0)正常,待详细排查
54103// - (void)testHttpsUp {
55104// __block QNResponseInfo *testInfo = nil;
0 commit comments