Skip to content

Commit fafc024

Browse files
Mark Pospeselmpospese
authored andcommitted
[Issue-9] apply same changes to download cancel test
1 parent 24f79ca commit fafc024

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Tests/YNetworkTests/NetworkManager/NetworkManagerDownloadTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ final class NetworkManagerDownloadTests: XCTestCase {
128128
let expectation = expectation(description: "Wait for download failure.")
129129
sut.expectation = expectation
130130

131+
let engine = try XCTUnwrap(sut.configuration?.networkEngine as? URLProtocolStubNetworkEngine)
132+
engine.autoResumesBackgroundTasks = false
133+
131134
URLProtocolStub.appendStub(withData: makeData(), statusCode: 200, type: .download)
132135

133136
XCTAssertNil(sut.receivedError)
134137

135-
let task = try XCTUnwrap(sut.submitBackgroundDownload(ImageDownloadRequest()) { _ in })
138+
let task = try XCTUnwrap(sut.submitBackgroundDownload(ImageDownloadRequest()) { _ in } as? URLSessionTask)
136139
task.cancel() // this will make it fail
140+
task.resume() // resume it
137141

138142
wait(for: [expectation], timeout: 1.0)
139143

@@ -150,7 +154,7 @@ final class NetworkManagerDownloadTests: XCTestCase {
150154

151155
XCTAssertNotNil(sut.submitBackgroundDownload(ImageDownloadRequest()) { _ in })
152156

153-
wait(for: [expectation], timeout: 1.0)
157+
wait(for: [expectation], timeout: timeout)
154158

155159
XCTAssertNotNil(sut.receivedError)
156160
}
@@ -179,7 +183,7 @@ final class NetworkManagerDownloadTests: XCTestCase {
179183

180184
XCTAssertNotNil(task, "Expected submit to return a task")
181185

182-
wait(for: [expectation], timeout: 1.0)
186+
wait(for: [expectation], timeout: timeout)
183187

184188
XCTAssertEqual(caught as? NetworkError, NetworkError.unauthenticated)
185189
}
@@ -209,7 +213,7 @@ final class NetworkManagerDownloadTests: XCTestCase {
209213

210214
XCTAssertNotNil(task, "Expected submit to return a task")
211215

212-
wait(for: [expectation], timeout: 1.0)
216+
wait(for: [expectation], timeout: timeout)
213217

214218
XCTAssertEqual((caught as? HttpError)?.statusCode, statusCode)
215219
}

0 commit comments

Comments
 (0)