Skip to content

Commit

Permalink
ThreadSafetyTests: add failing test where we load and store an image
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSB committed Feb 21, 2024
1 parent 8ecbfc8 commit 0c8d01c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Tests/NukeThreadSafetyTests/ThreadSafetyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,31 @@ class ThreadSafetyTests: XCTestCase {
}
queue.waitUntilAllOperationsAreFinished()
}

func testDataCacheMultipleThreadAccess() {
let aURL = URL(string: "https://example.com/image-01-small.jpeg")!
let imageData = Data(repeating: 1, count: 256 * 1024)

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

ImagePipeline.shared.cache.storeCachedData(imageData, for: ImageRequest.init(url: aURL))
ImagePipeline.shared.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

0 comments on commit 0c8d01c

Please sign in to comment.