<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Classes/Tests/StressTests.h</filename>
    </added>
    <added>
      <filename>Classes/Tests/StressTests.m</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -366,6 +366,14 @@ static BOOL isiPhoneOS2;
 	[stream close];
 }
 
+- (void)setDelegate:(id)newDelegate
+{
+	[[self cancelledLock] lock];
+	delegate = newDelegate;
+	[[self cancelledLock] unlock];
+}
+
+
 #pragma mark get information about this request
 
 - (BOOL)isFinished 
@@ -982,6 +990,8 @@ static BOOL isiPhoneOS2;
 
 - (void)setUploadProgressDelegate:(id)newDelegate
 {
+	[[self cancelledLock] lock];
+	
 	uploadProgressDelegate = newDelegate;
 	
 	// If the uploadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
@@ -995,11 +1005,14 @@ static BOOL isiPhoneOS2;
 		[invocation setArgument:&amp;max atIndex:2];
 		[invocation invoke];
 		
-	}	
+	}
+	[[self cancelledLock] unlock];
 }
 
 - (void)setDownloadProgressDelegate:(id)newDelegate
 {
+	[[self cancelledLock] lock];
+	
 	downloadProgressDelegate = newDelegate;
 	
 	// If the downloadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews
@@ -1012,6 +1025,7 @@ static BOOL isiPhoneOS2;
 		[invocation setArgument:&amp;max atIndex:2];
 		[invocation invokeWithTarget:downloadProgressDelegate];
 	}	
+	[[self cancelledLock] unlock];
 }
 
 
@@ -1248,13 +1262,13 @@ static BOOL isiPhoneOS2;
 		return;
 	}
 	// Let the queue know we are done
-	if ([queue respondsToSelector:@selector(requestDidFinish:)]) {
-		[queue performSelectorOnMainThread:@selector(requestDidFinish:) withObject:self waitUntilDone:[NSThread isMainThread]];		
+	if ([[self queue] respondsToSelector:@selector(requestDidFinish:)]) {
+		[[self queue] performSelectorOnMainThread:@selector(requestDidFinish:) withObject:self waitUntilDone:[NSThread isMainThread]];		
 	}
 	
 	// Let the delegate know we are done
-	if (didFinishSelector &amp;&amp; [delegate respondsToSelector:didFinishSelector]) {
-		[delegate performSelectorOnMainThread:didFinishSelector withObject:self waitUntilDone:[NSThread isMainThread]];		
+	if ([self didFinishSelector] &amp;&amp; [[self delegate] respondsToSelector:[self didFinishSelector]]) {
+		[[self delegate] performSelectorOnMainThread:[self didFinishSelector] withObject:self waitUntilDone:[NSThread isMainThread]];		
 	}
 }
 
@@ -1274,21 +1288,21 @@ static BOOL isiPhoneOS2;
 		[mRequest setError:theError];
 
 		// Let the queue know something went wrong
-		if ([queue respondsToSelector:@selector(requestDidFail:)]) {
-			[queue performSelectorOnMainThread:@selector(requestDidFail:) withObject:mRequest waitUntilDone:[NSThread isMainThread]];		
+		if ([[self queue] respondsToSelector:@selector(requestDidFail:)]) {
+			[[self queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:mRequest waitUntilDone:[NSThread isMainThread]];		
 		}
 	
 	} else {
 		[self setError:theError];
 		
 		// Let the queue know something went wrong
-		if ([queue respondsToSelector:@selector(requestDidFail:)]) {
-			[queue performSelectorOnMainThread:@selector(requestDidFail:) withObject:self waitUntilDone:[NSThread isMainThread]];		
+		if ([[self queue] respondsToSelector:@selector(requestDidFail:)]) {
+			[[self queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:self waitUntilDone:[NSThread isMainThread]];		
 		}
 		
 		// Let the delegate know something went wrong
-		if (didFailSelector &amp;&amp; [delegate respondsToSelector:didFailSelector]) {
-			[delegate performSelectorOnMainThread:didFailSelector withObject:self waitUntilDone:[NSThread isMainThread]];	
+		if ([self didFailSelector] &amp;&amp; [[self delegate] respondsToSelector:[self didFailSelector]]) {
+			[[self delegate] performSelectorOnMainThread:[self didFailSelector] withObject:self waitUntilDone:[NSThread isMainThread]];	
 		}
 	}
 }</diff>
      <filename>Classes/ASIHTTPRequest.m</filename>
    </modified>
    <modified>
      <diff>@@ -12,8 +12,6 @@
 
 @interface ASIHTTPRequestTests : ASITestCase {
 	float progress;
-	ASIHTTPRequest *cancelRequest;
-	NSDate *cancelStartDate;
 }
 
 - (void)testBasicDownload;
@@ -47,12 +45,6 @@
 - (void)testThrottlingDownloadBandwidth;
 - (void)testThrottlingUploadBandwidth;
 - (void)testMainThreadDelegateAuthenticationFailure;
-//- (void)testCancelStressTest;
-//- (void)performCancelRequest;
-//- (void)testRedirectStressTest;
-//- (void)performRedirectRequest;
 
 
-@property (retain,nonatomic) ASIHTTPRequest *cancelRequest;
-@property (retain, nonatomic) NSDate *cancelStartDate;
 @end</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.h</filename>
    </modified>
    <modified>
      <diff>@@ -1118,85 +1118,9 @@
 	
 }
 
-
-// This is a stress test that looks for thread-safety problems with cancelling requests
-// It will run for 30 seconds, creating a request, then cancelling it and creating another as soon as it gets some indication of progress
-// Uncomment to run on your local webserver. Do not use on a remote server, this test will create 1000s of requests!
-
-//- (void)testCancelStressTest
-//{
-//	[self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]];
-//	[self performCancelRequest];
-//	while ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
-//		[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
-//	}
-//	NSLog(@&quot;Stress test: DONE&quot;);
-//}
-//
-//- (void)performCancelRequest
-//{
-//	[self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@&quot;http://127.0.0.1/ASIHTTPRequest/tests/the_great_american_novel.txt&quot;]]];
-//	if ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
-//		[[self cancelRequest] setUserInfo:[NSDictionary dictionaryWithObject:@&quot;TryTryAgain&quot; forKey:@&quot;WhatShallIDoNext?&quot;]];
-//		[[self cancelRequest] setDownloadProgressDelegate:self];
-//		[[self cancelRequest] setShowAccurateProgress:YES];
-//		NSLog(@&quot;Stress test: Start request %@&quot;,[self cancelRequest]);
-//		[[self cancelRequest] startAsynchronous];
-//	}
-//}
-//
-
-// Another stress test that looks from problems when redirecting. Again, don't run on a non-local server
-
-//- (void)testRedirectStressTest
-//{
-//	[self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]];
-//	[self performRedirectRequest];
-//	while ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
-//		[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
-//	}
-//	NSLog(@&quot;Redirect stress test: DONE&quot;);
-//}
-//
-//- (void)performRedirectRequest
-//{
-//	[[ASIHTTPRequest sharedRequestQueue] setMaxConcurrentOperationCount:20];
-//	[self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@&quot;http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop&quot;]]];
-//	if ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
-//		NSLog(@&quot;Redirect stress test: Start request %@&quot;,[self cancelRequest]);
-//		[[self cancelRequest] startAsynchronous];
-//		[self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2];
-//	}
-//}
-//
-//- (void)cancelRedirectRequest
-//{
-//	NSLog(@&quot;Redirect stress test: Cancel request %@&quot;,[self cancelRequest]);
-//	[[self cancelRequest] cancel];
-//	[self performRedirectRequest];
-//}
-
-
 - (void)setProgress:(float)newProgress;
 {
 	progress = newProgress;
-	
-	// For cancel test
-	if (newProgress &gt; 0 &amp;&amp; [self cancelRequest]) {
-			
-		NSLog(@&quot;Stress test: Cancel request %@&quot;,[self cancelRequest]);
-		[[self cancelRequest] cancel];
-		
-		[self performSelector:@selector(performCancelRequest) withObject:nil afterDelay:0.2];
-		[self setCancelRequest:nil];
-	}
 }
 
-
-
-
-
-
-@synthesize cancelRequest;
-@synthesize cancelStartDate;
 @end
\ No newline at end of file</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.m</filename>
    </modified>
    <modified>
      <diff>@@ -40,6 +40,7 @@
 		B5C66396100A4C24004F3C96 /* ASIS3Request.m in Sources */ = {isa = PBXBuildFile; fileRef = B5C66394100A4C24004F3C96 /* ASIS3Request.m */; };
 		B5C66397100A4C24004F3C96 /* ASIS3Request.m in Sources */ = {isa = PBXBuildFile; fileRef = B5C66394100A4C24004F3C96 /* ASIS3Request.m */; };
 		B5C664BC100A6220004F3C96 /* ASIS3RequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B5C664BB100A6220004F3C96 /* ASIS3RequestTests.m */; };
+		B5EA45E0109B5A4100E920CB /* StressTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B5EA45DF109B5A4100E920CB /* StressTests.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
@@ -103,6 +104,8 @@
 		B5C664BA100A6220004F3C96 /* ASIS3RequestTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIS3RequestTests.h; sourceTree = &quot;&lt;group&gt;&quot;; };
 		B5C664BB100A6220004F3C96 /* ASIS3RequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIS3RequestTests.m; sourceTree = &quot;&lt;group&gt;&quot;; };
 		B5E3858B0F76606B00FD7857 /* Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = &quot;Tests-Info.plist&quot;; path = &quot;Mac Sample/Tests-Info.plist&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
+		B5EA45DE109B5A4100E920CB /* StressTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StressTests.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+		B5EA45DF109B5A4100E920CB /* StressTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StressTests.m; sourceTree = &quot;&lt;group&gt;&quot;; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -249,6 +252,8 @@
 				B55B5D1F0F76568E0064029C /* ASINetworkQueueTests.m */,
 				B5C664BA100A6220004F3C96 /* ASIS3RequestTests.h */,
 				B5C664BB100A6220004F3C96 /* ASIS3RequestTests.m */,
+				B5EA45DE109B5A4100E920CB /* StressTests.h */,
+				B5EA45DF109B5A4100E920CB /* StressTests.m */,
 				B50244191025D36B002B13E1 /* ProxyTests.h */,
 				B502441A1025D36B002B13E1 /* ProxyTests.m */,
 			);
@@ -367,6 +372,7 @@
 				B565297E101C8D01000499CF /* ASITestCase.m in Sources */,
 				B502441B1025D36B002B13E1 /* ProxyTests.m in Sources */,
 				B522D71F103074AC009A2D22 /* ASIInputStream.m in Sources */,
+				B5EA45E0109B5A4100E920CB /* StressTests.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};</diff>
      <filename>Mac.xcodeproj/project.pbxproj</filename>
    </modified>
    <modified>
      <diff>@@ -61,6 +61,8 @@
 		B5E2A9AC100C89D900B70E26 /* ASIS3ListRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B5E2A9AA100C89D900B70E26 /* ASIS3ListRequest.m */; };
 		B5E2A9AD100C89D900B70E26 /* ASIS3BucketObject.m in Sources */ = {isa = PBXBuildFile; fileRef = B5E2A9A7100C89D900B70E26 /* ASIS3BucketObject.m */; };
 		B5E2A9AE100C89D900B70E26 /* ASIS3ListRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B5E2A9AA100C89D900B70E26 /* ASIS3ListRequest.m */; };
+		B5EA45AA109B56D800E920CB /* StressTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B5EA45A9109B56D800E920CB /* StressTests.m */; };
+		B5EA45AB109B56D800E920CB /* StressTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B5EA45A9109B56D800E920CB /* StressTests.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -139,6 +141,8 @@
 		B5E2A9A8100C89D900B70E26 /* ASIS3ListRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIS3ListRequest.h; sourceTree = &quot;&lt;group&gt;&quot;; };
 		B5E2A9A9100C89D900B70E26 /* ASIS3BucketObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIS3BucketObject.h; sourceTree = &quot;&lt;group&gt;&quot;; };
 		B5E2A9AA100C89D900B70E26 /* ASIS3ListRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIS3ListRequest.m; sourceTree = &quot;&lt;group&gt;&quot;; };
+		B5EA45A8109B56D800E920CB /* StressTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StressTests.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+		B5EA45A9109B56D800E920CB /* StressTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StressTests.m; sourceTree = &quot;&lt;group&gt;&quot;; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -277,6 +281,8 @@
 				B55B60570F765A3C0064029C /* ASINetworkQueueTests.m */,
 				B5C6663C100A82D7004F3C96 /* ASIS3RequestTests.h */,
 				B5C6663D100A82D7004F3C96 /* ASIS3RequestTests.m */,
+				B5EA45A8109B56D800E920CB /* StressTests.h */,
+				B5EA45A9109B56D800E920CB /* StressTests.m */,
 				B5254FF81025F9BF00CF7BC4 /* ProxyTests.h */,
 				B5254FF71025F9BF00CF7BC4 /* ProxyTests.m */,
 			);
@@ -428,6 +434,7 @@
 				B5D145521029E20D004379B8 /* Reachability.m in Sources */,
 				B522DACF1030B2AB009A2D22 /* ASIInputStream.m in Sources */,
 				B59A87C3103EC6F200300252 /* ASIAuthenticationDialog.m in Sources */,
+				B5EA45AB109B56D800E920CB /* StressTests.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -452,6 +459,7 @@
 				B5D145511029E20D004379B8 /* Reachability.m in Sources */,
 				B522DACE1030B2AB009A2D22 /* ASIInputStream.m in Sources */,
 				B59A87C2103EC6F200300252 /* ASIAuthenticationDialog.m in Sources */,
+				B5EA45AA109B56D800E920CB /* StressTests.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};</diff>
      <filename>iPhone.xcodeproj/project.pbxproj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b09a955c21aca2f043f88382b35586d75f63dc56</id>
    </parent>
  </parents>
  <author>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </author>
  <url>http://github.com/pokeb/asi-http-request/commit/83cf858852c60bb8055915fea423a756a0a05567</url>
  <id>83cf858852c60bb8055915fea423a756a0a05567</id>
  <committed-date>2009-10-30T11:41:44-07:00</committed-date>
  <authored-date>2009-10-30T11:41:44-07:00</authored-date>
  <message>Added test and attempt to reproduce problems with setting delegates while request is running (no success so far)
Added additional safety measures to attempt to address this:
* Use cancelledLock around setDelegate methods
* Use accessors for delegates

Also moved stress tests to new file</message>
  <tree>a28e63b461d903652e8a3b7c2f1599a814707609</tree>
  <committer>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </committer>
</commit>
