Ben Copsey

Fix testAddingRequestsToQueueWhileInProgress

@@ -25,6 +25,7 @@ IMPORTANT @@ -25,6 +25,7 @@ IMPORTANT
25 BOOL request_didfail; 25 BOOL request_didfail;
26 BOOL request_succeeded; 26 BOOL request_succeeded;
27 float progress; 27 float progress;
  28 + int addedRequests;
28 29
29 NSOperationQueue *immediateCancelQueue; 30 NSOperationQueue *immediateCancelQueue;
30 NSMutableArray *failedRequests; 31 NSMutableArray *failedRequests;
@@ -213,7 +213,7 @@ IMPORTANT @@ -213,7 +213,7 @@ IMPORTANT
213 [[self addMoreRequestsQueue] setDownloadProgressDelegate:self]; 213 [[self addMoreRequestsQueue] setDownloadProgressDelegate:self];
214 [[self addMoreRequestsQueue] setDelegate:self]; 214 [[self addMoreRequestsQueue] setDelegate:self];
215 [[self addMoreRequestsQueue] setShowAccurateProgress:NO]; 215 [[self addMoreRequestsQueue] setShowAccurateProgress:NO];
216 - [[self addMoreRequestsQueue] setQueueDidFinishSelector:@selector(addMoreRequestsQueueFinished:)]; 216 + [[self addMoreRequestsQueue]setQueueDidFinishSelector:@selector(addMoreRequestsQueueFinished:)];
217 217
218 requestsFinishedCount = 0; 218 requestsFinishedCount = 0;
219 219
@@ -232,15 +232,22 @@ IMPORTANT @@ -232,15 +232,22 @@ IMPORTANT
232 [[self addMoreRequestsQueue] go]; 232 [[self addMoreRequestsQueue] go];
233 233
234 // Add another request to the queue each second for 5 seconds 234 // Add another request to the queue each second for 5 seconds
  235 + addedRequests = 0;
235 for (i=0; i<5; i++) { 236 for (i=0; i<5; i++) {
236 [self performSelector:@selector(addAnotherRequest) withObject:nil afterDelay:i]; 237 [self performSelector:@selector(addAnotherRequest) withObject:nil afterDelay:i];
237 } 238 }
238 239
239 - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]]; 240 + while (addedRequests < 5) {
  241 + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
  242 + }
  243 +
  244 + // Must wait or subsequent tests will reset our progress
  245 + [[self addMoreRequestsQueue] waitUntilAllOperationsAreFinished];
240 } 246 }
241 247
242 - (void)addAnotherRequest 248 - (void)addAnotherRequest
243 { 249 {
  250 + addedRequests++;
244 NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/the_great_american_novel_(abridged).txt"] autorelease]; 251 NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/the_great_american_novel_(abridged).txt"] autorelease];
245 ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; 252 ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
246 [request setDelegate:self]; 253 [request setDelegate:self];