AliSoftware / AliSoftware/OHHTTPStubs

Redirect stubbing not working reliably

未關閉
#230 8 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Objective-C
星號
5.1k
分支
597
PR 合併指標
30 天內沒有已合併 PR

描述

First of all, thanks for this great tool!
Sorry for the disorganized report

I've been having an issue that our redirect unit tests occasionally fail.
In the latest release I saw a fix that I was hoping to solve my problem ( #224) but unfortunately not.

Now I have a way to make the redirect stubbing fail reliably. A small modification to OHHTTPStubs.m:
```
[client URLProtocol:self wasRedirectedToRequest:redirectRequest redirectResponse:urlResponse];
+++ usleep(1000000)
```

With the above we get the failure 100% of the time.
I added a test to NSURLSessionTests.m:
```
- (void)test_Redirect
{
if ([NSURLSession class])
{
NSURLSession *session = [NSURLSession sharedSession];

NSDictionary* json = @{@"Success": @"Yes"};
[self _test_redirect_NSURLSession:session jsonForStub:json completion:^(NSError *errorResponse, NSHTTPURLResponse *redirectResponse, id jsonResponse) {
XCTAssertNil(errorResponse, @"Unexpected error");
XCTAssertNil(redirectResponse, @"Unexpected redirect response received");
XCTAssertEqualObjects(jsonResponse, json, @"Unexpected data received");
}];
}
else
{
NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n");
}
}
```

After inserting the sleep the data task completion handler starts receiving the redirect response instead of the response after the redirect.

I can fix it by not calling didReceiveResponse for the redirect (301 code) but based on #175 this does not seem to be a valid solution

I will investigate further but wanted to create a ticket in case anyone already have a clue about the root cause.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。