Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 49f9d13124793b4bbff0c3490af8e1326128e6df 1 parent 5fb6e03
michael authored committed
4 ASIHTTPRequest.m
@@ -166,8 +166,8 @@ - (BOOL)isFinished
166 166
167 167 - (void)cancel
168 168 {
169   - [super cancel];
170 169 [self failWithError:ASIRequestCancelledError];
  170 + [super cancel];
171 171 [self cancelLoad];
172 172 complete = YES;
173 173
@@ -1170,7 +1170,6 @@ - (void)handleStreamError
1170 1170 {
1171 1171 NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
1172 1172
1173   - [super cancel];
1174 1173 [self cancelLoad];
1175 1174 complete = YES;
1176 1175
@@ -1178,6 +1177,7 @@ - (void)handleStreamError
1178 1177
1179 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 1183 #pragma mark managing the session
2  ASINetworkQueueTests.h 100644 → 100755
@@ -15,6 +15,8 @@
15 15 ASIHTTPRequest *requestThatShouldFail;
16 16 ASINetworkQueue *networkQueue;
17 17 BOOL complete;
  18 + BOOL request_didfail;
  19 + BOOL request_succeeded;
18 20 float progress;
19 21 }
20 22
33 ASINetworkQueueTests.m 100644 → 100755
@@ -265,32 +265,41 @@ - (void)testProgressWithAuthentication
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 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 281 - (void)testWithNoListener
270 282 {
271   - complete = NO;
  283 + request_succeeded = NO;
  284 + request_didfail = NO;
272 285 networkQueue = [[ASINetworkQueue alloc] init];
273 286 [networkQueue setDownloadProgressDelegate:self];
274 287 [networkQueue setDelegate:self];
275 288 [networkQueue setShowAccurateProgress:YES];
  289 + [networkQueue setRequestDidFailSelector:@selector(requestFailedExpectedly:)];
  290 + [networkQueue setRequestDidFinishSelector:@selector(requestSucceededUnexpectedly:)];
276 291 [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
277 292
278 293 NSURL *url;
279 294 url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com:9999/i/logo.png"] autorelease];
280   - ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
281   - [networkQueue addOperation:request1];
  295 + requestThatShouldFail = [[ASIHTTPRequest alloc] initWithURL:url];
  296 + [networkQueue addOperation:requestThatShouldFail];
282 297
283 298 [networkQueue go];
284   -
285   - while (!complete) {
286   - CFRunLoopRunInMode(ASIHTTPRequestTestsRunMode,0.25,YES);
287   - }
288   -
289 299 [networkQueue waitUntilAllOperationsAreFinished];
290   -
291   - BOOL success = YES;
292   - GHAssertTrue(success,@"Should not have crashed");
293   -
  300 +
  301 + GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed");
  302 +
294 303 [networkQueue release];
295 304 }
296 305

0 comments on commit 49f9d13

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