michael
Committed by Ben Copsey

call fail selector again if the server is not reachable at all

@@ -166,8 +166,8 @@ static NSError *ASIUnableToCreateRequestError; @@ -166,8 +166,8 @@ static NSError *ASIUnableToCreateRequestError;
166 166
167 - (void)cancel 167 - (void)cancel
168 { 168 {
169 - [super cancel];  
170 [self failWithError:ASIRequestCancelledError]; 169 [self failWithError:ASIRequestCancelledError];
  170 + [super cancel];
171 [self cancelLoad]; 171 [self cancelLoad];
172 complete = YES; 172 complete = YES;
173 173
@@ -1170,7 +1170,6 @@ static NSError *ASIUnableToCreateRequestError; @@ -1170,7 +1170,6 @@ static NSError *ASIUnableToCreateRequestError;
1170 { 1170 {
1171 NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease]; 1171 NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
1172 1172
1173 - [super cancel];  
1174 [self cancelLoad]; 1173 [self cancelLoad];
1175 complete = YES; 1174 complete = YES;
1176 1175
@@ -1178,6 +1177,7 @@ static NSError *ASIUnableToCreateRequestError; @@ -1178,6 +1177,7 @@ static NSError *ASIUnableToCreateRequestError;
1178 1177
1179 [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"A connection failure occurred",NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]]; 1178 [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"A connection failure occurred",NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]];
1180 } 1179 }
  1180 + [super cancel];
1181 } 1181 }
1182 1182
1183 #pragma mark managing the session 1183 #pragma mark managing the session
@@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
15 ASIHTTPRequest *requestThatShouldFail; 15 ASIHTTPRequest *requestThatShouldFail;
16 ASINetworkQueue *networkQueue; 16 ASINetworkQueue *networkQueue;
17 BOOL complete; 17 BOOL complete;
  18 + BOOL request_didfail;
  19 + BOOL request_succeeded;
18 float progress; 20 float progress;
19 } 21 }
20 22
@@ -265,31 +265,40 @@ static CFStringRef ASIHTTPRequestTestsRunMode = CFSTR("ASIHTTPRequestTestsRunMod @@ -265,31 +265,40 @@ static CFStringRef ASIHTTPRequestTestsRunMode = CFSTR("ASIHTTPRequestTestsRunMod
265 265
266 } 266 }
267 267
  268 +- (void)requestFailedExpectedly:(ASIHTTPRequest *)request
  269 +{
  270 + request_didfail = YES;
  271 + BOOL success = (request == requestThatShouldFail);
  272 + GHAssertTrue(success,@"Wrong request failed");
  273 +}
  274 +
  275 +- (void)requestSucceededUnexpectedly:(ASIHTTPRequest *)request
  276 +{
  277 + request_succeeded = YES;
  278 +}
  279 +
268 //Connect to a port the server isn't listening on, and the read stream won't be created (Test + Fix contributed by Michael Krause) 280 //Connect to a port the server isn't listening on, and the read stream won't be created (Test + Fix contributed by Michael Krause)
269 - (void)testWithNoListener 281 - (void)testWithNoListener
270 { 282 {
271 - complete = NO; 283 + request_succeeded = NO;
  284 + request_didfail = NO;
272 networkQueue = [[ASINetworkQueue alloc] init]; 285 networkQueue = [[ASINetworkQueue alloc] init];
273 [networkQueue setDownloadProgressDelegate:self]; 286 [networkQueue setDownloadProgressDelegate:self];
274 [networkQueue setDelegate:self]; 287 [networkQueue setDelegate:self];
275 [networkQueue setShowAccurateProgress:YES]; 288 [networkQueue setShowAccurateProgress:YES];
  289 + [networkQueue setRequestDidFailSelector:@selector(requestFailedExpectedly:)];
  290 + [networkQueue setRequestDidFinishSelector:@selector(requestSucceededUnexpectedly:)];
276 [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; 291 [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
277 292
278 NSURL *url; 293 NSURL *url;
279 url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com:9999/i/logo.png"] autorelease]; 294 url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com:9999/i/logo.png"] autorelease];
280 - ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; 295 + requestThatShouldFail = [[ASIHTTPRequest alloc] initWithURL:url];
281 - [networkQueue addOperation:request1]; 296 + [networkQueue addOperation:requestThatShouldFail];
282 297
283 [networkQueue go]; 298 [networkQueue go];
284 -  
285 - while (!complete) {  
286 - CFRunLoopRunInMode(ASIHTTPRequestTestsRunMode,0.25,YES);  
287 - }  
288 -  
289 [networkQueue waitUntilAllOperationsAreFinished]; 299 [networkQueue waitUntilAllOperationsAreFinished];
290 300
291 - BOOL success = YES; 301 + GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed");
292 - GHAssertTrue(success,@"Should not have crashed");  
293 302
294 [networkQueue release]; 303 [networkQueue release];
295 } 304 }