Skip to content
Merged
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
16 changes: 6 additions & 10 deletions Tests/KingfisherTests/ImageDownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,27 @@ class ImageDownloaderTests: XCTestCase {
}

func testDownloadWithAsyncModifyingRequest() {
let downloadCompleted = expectation(description: #function)
let downloadTaskStarted = expectation(description: "downloadTaskStarted")
let exp = expectation(description: #function)
let downloadTaskStarted = LockIsolated(false)

let url = testURLs[0]
stub(url, data: testImageData)

let asyncModifier = AsyncURLModifier(url: url, onDownloadTaskStarted: { task in
XCTAssertNotNil(task)
downloadTaskStarted.fulfill()
downloadTaskStarted.setValue(true)
})

let someURL = URL(string: "some_strange_url")!
let task = downloader.downloadImage(with: someURL, options: [.requestModifier(asyncModifier)]) { result in
XCTAssertNotNil(result.value)
XCTAssertEqual(result.value?.url, url)
downloadCompleted.fulfill()
XCTAssertTrue(downloadTaskStarted.value)
exp.fulfill()
}
// The returned task is nil since the download is not starting immediately.
XCTAssertFalse(task.isInitialized)
XCTAssertEqual(
// `enforceOrder: true` requires the expectations to be fulfilled in order:
// `downloadTaskStarted` must happen before `downloadCompleted`.
XCTWaiter.wait(for: [downloadTaskStarted, downloadCompleted], timeout: 3, enforceOrder: true),
.completed
)
waitForExpectations(timeout: 3, handler: nil)
}

func testDownloadWithModifyingRequestToNil() {
Expand Down