Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1541)

Unified Diff: components/cronet/ios/test/cronet_http_test.mm

Issue 2776583004: Use 64kb read buffer in CRNHttpProtocolHandler on iOS. (Closed)
Patch Set: Address Andrei's comments, use RawHttpResponse. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/ios/test/cronet_http_test.mm
diff --git a/components/cronet/ios/test/cronet_http_test.mm b/components/cronet/ios/test/cronet_http_test.mm
index e1642feeaf9cbb5a6ad0cff8fdde7d7e7a03d6b1..1d72a2ac9416e4d2d3d7c4e38222b4eff19ce478 100644
--- a/components/cronet/ios/test/cronet_http_test.mm
+++ b/components/cronet/ios/test/cronet_http_test.mm
@@ -28,21 +28,19 @@
// Completion semaphore for this TestDelegate. When the request this delegate is
// attached to finishes (either successfully or with an error), this delegate
// signals this semaphore.
-@property(assign, nonatomic) dispatch_semaphore_t semaphore;
-
-// Body of response received by the request this delegate is attached to.
-@property(retain, nonatomic) NSString* responseBody;
+@property(assign, atomic) dispatch_semaphore_t semaphore;
// Error the request this delegate is attached to failed with, if any.
-@property(retain, nonatomic) NSError* error;
+@property(retain, atomic) NSError* error;
@end
@implementation TestDelegate
@synthesize semaphore = _semaphore;
-@synthesize responseBody = _responseBody;
@synthesize error = _error;
+NSMutableArray<NSData*>* _responseData;
+
- (id)init {
if (self = [super init]) {
_semaphore = dispatch_semaphore_create(0);
@@ -58,10 +56,25 @@
}
- (void)reset {
- _responseBody = nil;
+ [_responseData dealloc];
+ _responseData = nil;
_error = nil;
}
+- (NSString*)responseBody {
+ if (_responseData == nil) {
+ return nil;
+ }
+ NSMutableString* body = [NSMutableString string];
+ for (NSData* data in _responseData) {
+ [body appendString:[[NSString alloc] initWithData:data
+ encoding:NSUTF8StringEncoding]];
+ }
+ VLOG(3) << "responseBody size:" << [body length]
+ << " chunks:" << [_responseData count];
+ return body;
+}
+
- (void)URLSession:(NSURLSession*)session
didBecomeInvalidWithError:(NSError*)error {
}
@@ -93,13 +106,10 @@
- (void)URLSession:(NSURLSession*)session
dataTask:(NSURLSessionDataTask*)dataTask
didReceiveData:(NSData*)data {
- NSString* stringData =
- [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- if (_responseBody == nil) {
- _responseBody = stringData;
- } else {
- _responseBody = [_responseBody stringByAppendingString:stringData];
+ if (_responseData == nil) {
+ _responseData = [[NSMutableArray alloc] init];
}
+ [_responseData addObject:data];
}
- (void)URLSession:(NSURLSession*)session
@@ -154,7 +164,7 @@ class HttpTest : public ::testing::Test {
void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task) {
[delegate_ reset];
[task resume];
- int64_t deadline_ns = 1 * ns_in_second;
+ int64_t deadline_ns = 20 * ns_in_second;
dispatch_semaphore_wait([delegate_ semaphore],
kapishnikov 2017/04/19 18:19:01 Are we interested in the result of dispatch_semaph
mef 2017/04/19 19:04:48 Done.
dispatch_time(DISPATCH_TIME_NOW, deadline_ns));
}
@@ -164,7 +174,7 @@ class HttpTest : public ::testing::Test {
};
TEST_F(HttpTest, NSURLSessionReceivesData) {
- NSURL* url = net::NSURLWithGURL(GURL(grpc_support::kTestServerUrl));
+ NSURL* url = net::NSURLWithGURL(GURL(grpc_support::kTestServerSimpleUrl));
__block BOOL block_used = NO;
NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
[Cronet setRequestFilterBlock:^(NSURLRequest* request) {
@@ -175,18 +185,49 @@ TEST_F(HttpTest, NSURLSessionReceivesData) {
StartDataTaskAndWaitForCompletion(task);
EXPECT_TRUE(block_used);
EXPECT_EQ(nil, [delegate_ error]);
- EXPECT_STREQ(grpc_support::kHelloBodyValue,
+ EXPECT_STREQ(grpc_support::kSimpleBodyValue,
base::SysNSStringToUTF8([delegate_ responseBody]).c_str());
}
+TEST_F(HttpTest, NSURLSessionReceivesBigHttpDataLoop) {
+ int iterations = 50;
+ long size = 10 * 1024 * 1024;
+ LOG(INFO) << "Downloading " << size << " bytes " << iterations << " times.";
+ NSTimeInterval elapsed_avg = 0;
+ NSTimeInterval elapsed_max = 0;
+ NSURL* url = net::NSURLWithGURL(GURL(TestServer::PrepareBigDataURL(size)));
+ for (int i = 0; i < iterations; ++i) {
+ [delegate_ reset];
+ __block BOOL block_used = NO;
+ NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
+ [Cronet setRequestFilterBlock:^(NSURLRequest* request) {
+ block_used = YES;
+ EXPECT_EQ([request URL], url);
+ return YES;
+ }];
+ NSDate* date = [NSDate date];
+ StartDataTaskAndWaitForCompletion(task);
+ NSTimeInterval elapsed = [date timeIntervalSinceNow] * -1000.0;
+ elapsed_avg += elapsed;
+ if (elapsed > elapsed_max)
+ elapsed_max = elapsed;
+ EXPECT_TRUE(block_used);
+ EXPECT_EQ(nil, [delegate_ error]);
+ }
+ // Release the response buffer.
+ TestServer::PrepareBigDataURL(0);
+ LOG(INFO) << "Elapsed Average:" << elapsed_avg / iterations
+ << "ms Max:" << elapsed_max << "ms";
+}
+
TEST_F(HttpTest, GetGlobalMetricsDeltas) {
NSData* delta1 = [Cronet getGlobalMetricsDeltas];
- NSURL* url = net::NSURLWithGURL(GURL(grpc_support::kTestServerUrl));
+ NSURL* url = net::NSURLWithGURL(GURL(grpc_support::kTestServerSimpleUrl));
NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
StartDataTaskAndWaitForCompletion(task);
EXPECT_EQ(nil, [delegate_ error]);
- EXPECT_STREQ(grpc_support::kHelloBodyValue,
+ EXPECT_STREQ(grpc_support::kSimpleBodyValue,
base::SysNSStringToUTF8([delegate_ responseBody]).c_str());
NSData* delta2 = [Cronet getGlobalMetricsDeltas];
« no previous file with comments | « no previous file | components/cronet/ios/test/start_cronet.mm » ('j') | components/cronet/ios/test/test_server.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698