Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Test cases, Fix potential memory leaks by use of NSURLSession #250

Merged
merged 4 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# OHHTTPStubs — CHANGELOG

## Master

* Fixed potential memory leaks with use of NSURLSession as detected by our devs.
[@mikelupo](https://github.com/mikelupo
[#250](https://github.com/AliSoftware/OHHTTPStubs/pull/250)
* Add precondition assertions in `isScheme` and `isHost` matchers and some documentation in `isHost`, `isScheme` and `isPath`.
[@Liquidsoul](https://github.com/Liquidsoul)
[#248](https://github.com/AliSoftware/OHHTTPStubs/pull/248)
Expand Down
1 change: 1 addition & 0 deletions OHHTTPStubs/UnitTests/Test Suites/MocktailTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ - (void)setUp
- (void)tearDown
{
[super tearDown];
[self.session invalidateAndCancel];
self.session = nil;
}

Expand Down
16 changes: 16 additions & 0 deletions OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ - (void)test_SharedNSURLSession
XCTAssertNil(redirectResponse, @"Unexpected redirect response received");
XCTAssertEqualObjects(jsonResponse, json, @"Unexpected data received");
}];

[session finishTasksAndInvalidate];
}
else
{
Expand All @@ -220,6 +222,8 @@ - (void)test_NSURLSessionDefaultConfig
XCTAssertNil(redirectResponse, @"Unexpected redirect response received");
XCTAssertEqualObjects(jsonResponse, json, @"Unexpected data received");
}];

[session finishTasksAndInvalidate];
}
else
{
Expand All @@ -243,6 +247,8 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects
XCTAssertEqual(301, [redirectResponse statusCode], @"Expected 301 redirect");
XCTAssertNil(jsonResponse, @"Unexpected data received");
}];

[session finishTasksAndInvalidate];
}
else
{
Expand All @@ -268,6 +274,8 @@ - (void)test_NSURLSessionEphemeralConfig
XCTAssertNil(redirectResponse, @"Unexpected redirect response received");
XCTAssertEqualObjects(jsonResponse, json, @"Unexpected data received");
}];

[session finishTasksAndInvalidate];
}
else
{
Expand Down Expand Up @@ -296,6 +304,8 @@ - (void)test_NSURLSessionDefaultConfig_Disabled
XCTAssertNil(redirectResponse, @"Redirect response should not have been received as stubs should be disabled");
XCTAssertNil(jsonResponse, @"Data should not have been received as stubs should be disabled");
}];

[session finishTasksAndInvalidate];
}
else
{
Expand Down Expand Up @@ -325,6 +335,8 @@ - (void)test_NSURLSession_DataTask_DelegateMethods
[self waitForExpectationsWithTimeout:5 handler:nil];

XCTAssertEqualObjects(_receivedData, expectedResponse, @"Unexpected response");

[session finishTasksAndInvalidate];
}
else
{
Expand Down Expand Up @@ -370,6 +382,8 @@ - (void)test_NSURLSessionCustomHTTPBody
[self waitForExpectationsWithTimeout:5 handler:nil];

XCTAssertNil(_receivedData, @"Unexpected response: HTTP body check should not be successful");

[session finishTasksAndInvalidate];
}
else
{
Expand Down Expand Up @@ -403,6 +417,8 @@ - (void)test_NSURLSessionNativeHTTPBody

[self waitForExpectationsWithTimeout:5 handler:nil];
XCTAssertNil(_receivedData, @"[request HTTPBody] is not expected to work. If this has been fixed, the OHHTTPStubs_HTTPBody can be removed.");

[session finishTasksAndInvalidate];
}
else
{
Expand Down