Skip to content
Browse files

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

  • Loading branch information...
1 parent 5fb6e03 commit 49f9d13124793b4bbff0c3490af8e1326128e6df michael committed with Mar 12, 2009
Showing with 25 additions and 14 deletions.
  1. +2 −2 ASIHTTPRequest.m
  2. +2 −0 ASINetworkQueueTests.h
  3. +21 −12 ASINetworkQueueTests.m
View
4 ASIHTTPRequest.m
@@ -166,8 +166,8 @@ - (BOOL)isFinished
- (void)cancel
{
- [super cancel];
[self failWithError:ASIRequestCancelledError];
+ [super cancel];
[self cancelLoad];
complete = YES;
@@ -1170,14 +1170,14 @@ - (void)handleStreamError
{
NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
- [super cancel];
[self cancelLoad];
complete = YES;
if (!error) { // We may already have handled this error
[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
View
2 ASINetworkQueueTests.h 100644 → 100755
@@ -15,6 +15,8 @@
ASIHTTPRequest *requestThatShouldFail;
ASINetworkQueue *networkQueue;
BOOL complete;
+ BOOL request_didfail;
+ BOOL request_succeeded;
float progress;
}
View
33 ASINetworkQueueTests.m 100644 → 100755
@@ -265,32 +265,41 @@ - (void)testProgressWithAuthentication
}
+- (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];
}

0 comments on commit 49f9d13

Please sign in to comment.
Something went wrong with that request. Please try again.