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

ThreadSafetyTests: add failing test where we load and store an image #755

Merged
merged 2 commits into from
Mar 3, 2024
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
26 changes: 26 additions & 0 deletions Tests/NukeThreadSafetyTests/ThreadSafetyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ class ThreadSafetyTests: XCTestCase {
}
queue.waitUntilAllOperationsAreFinished()
}

func testDataCacheMultipleThreadAccess() {
let aURL = URL(string: "https://example.com/image-01-small.jpeg")!
let imageData = Test.data(name: "fixture", extension: "jpeg")

let expectSuccessFromCache = self.expectation(description: "one successful load, from cache")
expectSuccessFromCache.expectedFulfillmentCount = 1
expectSuccessFromCache.assertForOverFulfill = true

let pipeline = ImagePipeline(configuration: .withDataCache)
pipeline.cache.storeCachedData(imageData, for: ImageRequest.init(url: aURL))
pipeline.loadImage(with: aURL) { result in
switch result {
case .success(let response):
if response.cacheType == .memory || response.cacheType == .disk {
expectSuccessFromCache.fulfill()
} else {
XCTFail("didn't load that just cached image data: \(response)")
}
case .failure:
XCTFail("didn't load that just cached image data")
}
}

wait(for: [expectSuccessFromCache], timeout: 2)
}
}

final class OperationThreadSafetyTests: XCTestCase {
Expand Down
Loading