Browse files

Don't cancel a request if it has already finished

Closes gh-11
  • Loading branch information...
1 parent d00b47c commit 35fd545f67e14acb0f12cfb873805f0967693324 @pokeb committed Oct 31, 2009
Showing with 9 additions and 6 deletions.
  1. +1 −1 Classes/ASIHTTPRequest.m
  2. +8 −5 Classes/Tests/ASINetworkQueueTests.m
View
2 Classes/ASIHTTPRequest.m
@@ -392,7 +392,7 @@ - (void)cancel
{
[[self cancelledLock] lock];
- if ([self isCancelled]) {
+ if ([self isCancelled] || [self complete]) {
[[self cancelledLock] unlock];
return;
}
View
13 Classes/Tests/ASINetworkQueueTests.m
@@ -621,11 +621,11 @@ - (void)testCancelStressTest
// As soon as one request finishes or fails, we'll cancel the others and ensure that no requests are both finished and failed
- (void)testImmediateCancel
{
- [self setFailedRequests:[[[NSMutableArray alloc] init] autorelease]];
- [self setFinishedRequests:[[[NSMutableArray alloc] init] autorelease]];
+ [self setFailedRequests:[NSMutableArray array]];
+ [self setFinishedRequests:[NSMutableArray array]];
[self setImmediateCancelQueue:[[[NSOperationQueue alloc] init] autorelease]];
int i;
- for (i=0; i<25; i++) {
+ for (i=0; i<10; i++) {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setDelegate:self];
[request setDidFailSelector:@selector(immediateCancelFail:)];
@@ -637,7 +637,7 @@ - (void)testImmediateCancel
- (void)immediateCancelFail:(ASIHTTPRequest *)request
{
- [[self immediateCancelQueue] cancelAllOperations];
+ NSLog(@"Cancel %@",request);
if ([[self failedRequests] containsObject:request]) {
GHFail(@"A request called its fail delegate method twice");
}
@@ -648,11 +648,13 @@ - (void)immediateCancelFail:(ASIHTTPRequest *)request
if ([[self failedRequests] count]+[[self finishedRequests] count] > 25) {
GHFail(@"We got more than 25 delegate fail/finish calls - this shouldn't happen!");
}
+ [[self immediateCancelQueue] cancelAllOperations];
+
}
- (void)immediateCancelFinish:(ASIHTTPRequest *)request
{
- [[self immediateCancelQueue] cancelAllOperations];
+ NSLog(@"Finish %@",request);
if ([[self finishedRequests] containsObject:request]) {
GHFail(@"A request called its finish delegate method twice");
}
@@ -663,6 +665,7 @@ - (void)immediateCancelFinish:(ASIHTTPRequest *)request
if ([[self failedRequests] count]+[[self finishedRequests] count] > 25) {
GHFail(@"We got more than 25 delegate fail/finish calls - this shouldn't happen!");
}
+ [[self immediateCancelQueue] cancelAllOperations];
}
// Ensure class convenience constructor returns an instance of our subclass

0 comments on commit 35fd545

Please sign in to comment.