Skip to content

Commit

Permalink
Update testDataCacheMultipleThreadAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Mar 3, 2024
1 parent 3b4c97f commit 52bb8f7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Tests/NukeThreadSafetyTests/ThreadSafetyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,21 @@ class ThreadSafetyTests: XCTestCase {
queue.waitUntilAllOperationsAreFinished()
}

func testDataCacheMultipleThreadAccess() {
func testDataCacheMultipleThreadAccess() throws {
let cache = try DataCache(name: UUID().uuidString)

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))
let pipeline = ImagePipeline {
$0.dataCache = cache
$0.dataLoader = MockDataLoader()
}
pipeline.cache.storeCachedData(imageData, for: ImageRequest(url: aURL))
pipeline.loadImage(with: aURL) { result in
switch result {
case .success(let response):
Expand All @@ -189,6 +194,8 @@ class ThreadSafetyTests: XCTestCase {
}

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

try? FileManager.default.removeItem(at: cache.path)
}
}

Expand Down

0 comments on commit 52bb8f7

Please sign in to comment.