michael
Committed by Ben Copsey

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

... ... @@ -166,8 +166,8 @@ static NSError *ASIUnableToCreateRequestError;
- (void)cancel
{
[super cancel];
[self failWithError:ASIRequestCancelledError];
[super cancel];
[self cancelLoad];
complete = YES;
... ... @@ -1170,7 +1170,6 @@ static NSError *ASIUnableToCreateRequestError;
{
NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
[super cancel];
[self cancelLoad];
complete = YES;
... ... @@ -1178,6 +1177,7 @@ static NSError *ASIUnableToCreateRequestError;
[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"A connection failure occurred",NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]];
}
[super cancel];
}
#pragma mark managing the session
... ...
... ... @@ -15,6 +15,8 @@
ASIHTTPRequest *requestThatShouldFail;
ASINetworkQueue *networkQueue;
BOOL complete;
BOOL request_didfail;
BOOL request_succeeded;
float progress;
}
... ...
... ... @@ -265,32 +265,41 @@ static CFStringRef ASIHTTPRequestTestsRunMode = CFSTR("ASIHTTPRequestTestsRunMod
}
- (void)requestFailedExpectedly:(ASIHTTPRequest *)request
{
request_didfail = YES;
BOOL success = (request == requestThatShouldFail);
GHAssertTrue(success,@"Wrong request failed");
}
- (void)requestSucceededUnexpectedly:(ASIHTTPRequest *)request
{
request_succeeded = YES;
}
//Connect to a port the server isn't listening on, and the read stream won't be created (Test + Fix contributed by Michael Krause)
- (void)testWithNoListener
{
complete = NO;
request_succeeded = NO;
request_didfail = NO;
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue setDownloadProgressDelegate:self];
[networkQueue setDelegate:self];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setRequestDidFailSelector:@selector(requestFailedExpectedly:)];
[networkQueue setRequestDidFinishSelector:@selector(requestSucceededUnexpectedly:)];
[networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
NSURL *url;
url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com:9999/i/logo.png"] autorelease];
ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[networkQueue addOperation:request1];
requestThatShouldFail = [[ASIHTTPRequest alloc] initWithURL:url];
[networkQueue addOperation:requestThatShouldFail];
[networkQueue go];
while (!complete) {
CFRunLoopRunInMode(ASIHTTPRequestTestsRunMode,0.25,YES);
}
[networkQueue waitUntilAllOperationsAreFinished];
BOOL success = YES;
GHAssertTrue(success,@"Should not have crashed");
GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed");
[networkQueue release];
}
... ...