AliSoftware / AliSoftware/OHHTTPStubs

Redirect stubbing not working reliably

オープン
#230 コメント 8 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。