Tweak stress tests to prevent more than one request being added at the same time, causing exceptions
Showing
2 changed files
with
9 additions
and
0 deletions
@@ -23,6 +23,7 @@ | @@ -23,6 +23,7 @@ | ||
23 | ASIHTTPRequest *cancelRequest; | 23 | ASIHTTPRequest *cancelRequest; |
24 | NSDate *cancelStartDate; | 24 | NSDate *cancelStartDate; |
25 | MyDelegate *delegate; | 25 | MyDelegate *delegate; |
26 | + NSLock *createRequestLock; | ||
26 | } | 27 | } |
27 | 28 | ||
28 | - (void)testCancelStressTest; | 29 | - (void)testCancelStressTest; |
@@ -37,4 +38,5 @@ | @@ -37,4 +38,5 @@ | ||
37 | @property (retain) ASIHTTPRequest *cancelRequest; | 38 | @property (retain) ASIHTTPRequest *cancelRequest; |
38 | @property (retain) NSDate *cancelStartDate; | 39 | @property (retain) NSDate *cancelStartDate; |
39 | @property (retain) MyDelegate *delegate; | 40 | @property (retain) MyDelegate *delegate; |
41 | +@property (retain) NSLock *createRequestLock; | ||
40 | @end | 42 | @end |
@@ -61,6 +61,7 @@ IMPORTANT | @@ -61,6 +61,7 @@ IMPORTANT | ||
61 | 61 | ||
62 | - (void)testRedirectStressTest | 62 | - (void)testRedirectStressTest |
63 | { | 63 | { |
64 | + [self setCreateRequestLock:[[[NSLock alloc] init] autorelease]]; | ||
64 | [self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]]; | 65 | [self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]]; |
65 | [self performRedirectRequest]; | 66 | [self performRedirectRequest]; |
66 | while ([[self cancelStartDate] timeIntervalSinceNow] > 0) { | 67 | while ([[self cancelStartDate] timeIntervalSinceNow] > 0) { |
@@ -71,6 +72,7 @@ IMPORTANT | @@ -71,6 +72,7 @@ IMPORTANT | ||
71 | 72 | ||
72 | - (void)performRedirectRequest | 73 | - (void)performRedirectRequest |
73 | { | 74 | { |
75 | + [createRequestLock lock]; | ||
74 | [[ASIHTTPRequest sharedRequestQueue] setMaxConcurrentOperationCount:20]; | 76 | [[ASIHTTPRequest sharedRequestQueue] setMaxConcurrentOperationCount:20]; |
75 | [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop"]]]; | 77 | [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop"]]]; |
76 | if ([[self cancelStartDate] timeIntervalSinceNow] > 0) { | 78 | if ([[self cancelStartDate] timeIntervalSinceNow] > 0) { |
@@ -78,6 +80,7 @@ IMPORTANT | @@ -78,6 +80,7 @@ IMPORTANT | ||
78 | [[self cancelRequest] startAsynchronous]; | 80 | [[self cancelRequest] startAsynchronous]; |
79 | [self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2]; | 81 | [self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2]; |
80 | } | 82 | } |
83 | + [createRequestLock unlock]; | ||
81 | } | 84 | } |
82 | 85 | ||
83 | - (void)cancelRedirectRequest | 86 | - (void)cancelRedirectRequest |
@@ -90,6 +93,7 @@ IMPORTANT | @@ -90,6 +93,7 @@ IMPORTANT | ||
90 | // Ensures we can set the delegate while the request is running without problems | 93 | // Ensures we can set the delegate while the request is running without problems |
91 | - (void)testSetDelegate | 94 | - (void)testSetDelegate |
92 | { | 95 | { |
96 | + [self setCreateRequestLock:[[[NSLock alloc] init] autorelease]]; | ||
93 | [self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]]; | 97 | [self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]]; |
94 | [self performSetDelegateRequest]; | 98 | [self performSetDelegateRequest]; |
95 | while ([[self cancelStartDate] timeIntervalSinceNow] > 0) { | 99 | while ([[self cancelStartDate] timeIntervalSinceNow] > 0) { |
@@ -102,6 +106,7 @@ IMPORTANT | @@ -102,6 +106,7 @@ IMPORTANT | ||
102 | { | 106 | { |
103 | [self setDelegate:nil]; | 107 | [self setDelegate:nil]; |
104 | 108 | ||
109 | + [createRequestLock lock]; | ||
105 | [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/the_great_american_novel.txt"]]]; | 110 | [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/the_great_american_novel.txt"]]]; |
106 | if ([[self cancelStartDate] timeIntervalSinceNow] > 0) { | 111 | if ([[self cancelStartDate] timeIntervalSinceNow] > 0) { |
107 | [self setDelegate:[[[MyDelegate alloc] init] autorelease]]; | 112 | [self setDelegate:[[[MyDelegate alloc] init] autorelease]]; |
@@ -112,6 +117,7 @@ IMPORTANT | @@ -112,6 +117,7 @@ IMPORTANT | ||
112 | [[self cancelRequest] startAsynchronous]; | 117 | [[self cancelRequest] startAsynchronous]; |
113 | [self performSelectorInBackground:@selector(cancelSetDelegateRequest) withObject:nil]; | 118 | [self performSelectorInBackground:@selector(cancelSetDelegateRequest) withObject:nil]; |
114 | } | 119 | } |
120 | + [createRequestLock unlock]; | ||
115 | } | 121 | } |
116 | 122 | ||
117 | - (void)cancelSetDelegateRequest | 123 | - (void)cancelSetDelegateRequest |
@@ -141,4 +147,5 @@ IMPORTANT | @@ -141,4 +147,5 @@ IMPORTANT | ||
141 | @synthesize cancelRequest; | 147 | @synthesize cancelRequest; |
142 | @synthesize cancelStartDate; | 148 | @synthesize cancelStartDate; |
143 | @synthesize delegate; | 149 | @synthesize delegate; |
150 | +@synthesize createRequestLock; | ||
144 | @end | 151 | @end |
-
Please register or login to post a comment